Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aarontharris committed Sep 11, 2013
0 parents commit e05290e
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Loopd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
64 changes: 64 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Loopd</groupId>
<artifactId>Loopd</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Loopd</name>
<description>Loopd</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source />
<target />
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>oracleReleases</id>
<name>Oracle Released Java Packages</name>
<url>http://download.oracle.com/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>spy</id>
<name>Spy Repository</name>
<layout>default</layout>
<url>http://files.couchbase.com/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
11 changes: 11 additions & 0 deletions src/com/loopd/LoopdGuiceModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.loopd;

import com.google.inject.AbstractModule;

public class LoopdGuiceModule extends AbstractModule {

@Override
protected void configure() {
}

}
12 changes: 12 additions & 0 deletions src/com/loopd/SampleService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.loopd;

import com.google.inject.Singleton;

@Singleton
public class SampleService {

public void blah() {
System.out.println( "Hello Guice" );
}

}
92 changes: 92 additions & 0 deletions src/com/loopd/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.loopd;

import java.net.InetSocketAddress;
import java.util.Set;

import net.spy.memcached.MemcachedClient;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;

public class Test {
private static Injector injector;

@Inject
private SampleService svc;

public Test() {
injector.injectMembers( this );
}

public static void main( String args[] ) {
injector = Guice.createInjector( new LoopdGuiceModule() );
testGuice();
testMongoDB();
testMemcached();
}

public static void testGuice() {
Test t = new Test();
t.svc.blah();
}

public static void testMemcached() {
try {
// anything further than 30 days from now will instead
// be interpreted as unixtime -- seconds since Jan 1 1970.
int maxTimeFromNow = 60 * 60 * 24 * 30;

MemcachedClient c = new MemcachedClient( new InetSocketAddress( "127.0.0.1", 11211 ) );
String key = "someKey";
c.set( key, 3600, "somevalue" );

String value = (String) c.get( key );
System.out.println( String.format( "'%s'='%s'", key, value ) );

} catch ( Exception e ) {
System.err.println( e.getMessage() );
e.printStackTrace();
}
}

public static void testMongoDB() {
try {
// JsonObject obj = new JsonObject();
// obj.addProperty( "key1", "value1" );
// System.out.println( obj.toString() );

// To directly connect to a single MongoDB server (note that this will not auto-discover the primary even
// if it's a member of a replica set:
MongoClient mongoClient = new MongoClient( "127.0.0.1", 26017 );

DB db = mongoClient.getDB( "loopd" );

// db.addUser( { user: "loopuser", pwd: "macmacmac", roles: [ "readWrite" ] } )
boolean auth = db.authenticate( "loopuser", "macmacmac".toCharArray() );

Set<String> colls = db.getCollectionNames();
for ( String s : colls ) {
System.out.println( s );
}

for ( String collectionName : db.getCollectionNames() ) {
DBCollection collection = db.getCollection( collectionName );
DBCursor cursor = collection.find();
while ( cursor.hasNext() ) {
DBObject obj = cursor.next();
for ( String key : obj.keySet() ) {
System.out.println( String.format( "%s.%s='%s'", collectionName, key, obj.get( key ) ) );
}
}
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
}

0 comments on commit e05290e

Please sign in to comment.