-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
3,979 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Cocaine Client | ||
|
||
## Usage Example | ||
|
||
```java | ||
package example; | ||
|
||
import cocaine.Locator; | ||
import cocaine.Service; | ||
import org.apache.log4j.Logger; | ||
import rx.Observable; | ||
import rx.functions.Action1; | ||
import rx.functions.Func1; | ||
import rx.functions.Func2; | ||
|
||
/** | ||
* @author Anton Bobukh <abobukh@yandex-team.ru> | ||
*/ | ||
public class Example { | ||
|
||
private static final Logger logger = Logger.getLogger(Example.class); | ||
|
||
public static void main(String[] args) throws Exception { | ||
try (Locator locator = Locator.create()) { | ||
|
||
Service echo = locator.service("echo"); | ||
Observable<byte[]> response = echo.invoke("enqueue", "invoke", "10".getBytes()); | ||
|
||
Observable<String> strings = response.map(new Func1<byte[], String>() { | ||
@Override | ||
public String call(byte[] bytes) { | ||
return new String(bytes); | ||
} | ||
}).doOnNext(new Action1<String>() { | ||
@Override | ||
public void call(String value) { | ||
logger.info("Received: " + value); | ||
} | ||
}); | ||
|
||
long max = strings.take(5).map(new Func1<String, Long>() { | ||
@Override | ||
public Long call(String value) { | ||
return Long.parseLong(value); | ||
} | ||
}).reduce(new Func2<Long, Long, Long>() { | ||
@Override | ||
public Long call(Long max, Long current) { | ||
return Math.max(max, current); | ||
} | ||
}).toBlocking().single(); | ||
logger.info("Max: " + max); | ||
|
||
String aggregated = strings.skip(5).filter(new Func1<String, Boolean>() { | ||
@Override | ||
public Boolean call(String value) { | ||
return value.length() < 2; | ||
} | ||
}).reduce("", new Func2<String, String, String>() { | ||
@Override | ||
public String call(String result, String current) { | ||
return result + " " + current; | ||
} | ||
}).toBlocking().single().trim(); | ||
logger.info("Aggregated: " + aggregated); | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
|
||
<parent> | ||
<groupId>ru.yandex</groupId> | ||
<artifactId>cocaine</artifactId> | ||
<version>0.11.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>ru.yandex.cocaine</groupId> | ||
<artifactId>cocaine-client</artifactId> | ||
<version>0.11.1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Cocaine-Client</name> | ||
<description>Client for Cocaine Application Engine.</description> | ||
|
||
<prerequisites> | ||
<maven>3.0</maven> | ||
</prerequisites> | ||
|
||
<properties> | ||
<test.include>*Test.java</test.include> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>cocaine-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-all</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.msgpack</groupId> | ||
<artifactId>msgpack</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.netflix.rxjava</groupId> | ||
<artifactId>rxjava-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
cocaine-client/src/main/java/cocaine/ServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cocaine; | ||
|
||
/** | ||
* @author Anton Bobukh <abobukh@yandex-team.ru> | ||
*/ | ||
public class ServiceException extends CocaineException { | ||
|
||
private final String service; | ||
|
||
public ServiceException(String service, String message) { | ||
super(service + " - " + message); | ||
this.service = service; | ||
} | ||
|
||
public String getService() { | ||
return service; | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.