https://github.com/avh4/socketactor
SocketChannel facade for actor frameworks
https://github.com/avh4/socketactor
Last synced: 3 months ago
JSON representation
SocketChannel facade for actor frameworks
- Host: GitHub
- URL: https://github.com/avh4/socketactor
- Owner: avh4
- Created: 2013-11-23T22:20:49.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-11-24T23:52:10.000Z (over 11 years ago)
- Last Synced: 2025-02-07T17:37:07.501Z (5 months ago)
- Language: Java
- Size: 219 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](http://travis-ci.org/avh4/socketactor)
## socketactor-jumi
Provides `SocketChannelActor`, making it easy to create TCP clients/servers using the [jumi-actors framework](http://jumi.fi/actors.html).
### Usage
Add the following dependencies to your `pom.xml`:
```xml
net.avh4.util.socket
socketactor-jumi
0.0.1
```To create a TCP client, you will first need to initialize `jumi-actors`:
```java
ExecutorService threadPool = Executors.newCachedThreadPool();
Actors actors = new MultiThreadedActors(threadPool,
new DynamicEventizerProvider(),
new CrashEarlyFailureHandler(),
new PrintStreamMessageLogger(System.out));
ActorThread actorThread = actors.startActorThread();
```Now you can create your `received` and `disconnected` callbacks: (If your TCP protocol is not line-based, use `BytesListener` instead of `LinesListener`.)
```java
ActorRef socket;
ActorRef listener = actorThread.bindActor(LineListener.class,
new LineListener() {
@Override public void receivedLine(String line) {
System.out.println("RECEIVED: " + line);
socket.tell().next();
}@Override public void disconnected(Throwable cause) {
System.out.println("DISCONNECTED: " + cause.getLocalizedMessage());
}
});
```Now connect your client to a server: (If your TCP protocol is not line-based, use `SocketChannelActor.bytesSocketChannelActor` instead of `linesSocketChannelActor`.)
```java
socket = actorThread.bindActor(Socket.class,
SocketChannelActor.linesSocketChannelActor(host, port, listener));socket.tell().connect(listener);
socket.tell().write(listener, "currentsong\n".getBytes());
```## Build commands
* [Mutation coverage](http://pitest.org/): `mvn clean test org.pitest:pitest-maven:mutationCoverage`