https://github.com/clickermonkey/surfice
A Java library centered around the concept of a Service, which is a glorified thread that continually loops performing some job and handling events sent to the Service.
https://github.com/clickermonkey/surfice
Last synced: 11 months ago
JSON representation
A Java library centered around the concept of a Service, which is a glorified thread that continually loops performing some job and handling events sent to the Service.
- Host: GitHub
- URL: https://github.com/clickermonkey/surfice
- Owner: ClickerMonkey
- License: osl-3.0
- Created: 2013-04-30T18:07:22.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-11-15T20:51:15.000Z (about 12 years ago)
- Last Synced: 2025-01-27T10:23:09.620Z (about 1 year ago)
- Language: Java
- Size: 246 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
surfice
=======

A Java library centered around the concept of a Service, which is a glorified thread that continually loops performing some job and handling events sent to the Service.
**Features**
- Services can be started, paused, resumed, and stopped whenever. This is entirely thread-safe.
- A service can be interrupted in several fashions, it can be paused/stopped immediately, after it's done executing the current task, after it's done handling events, or after the service is done entirely.
- A service can have multiple listeners that are notified when it receives an event, it has just executed it's main piece of code, it has started, it has been paused, it was resumed, and it has stopped.
**Documentation**
- [JavaDoc](http://gh.magnos.org/?r=http://clickermonkey.github.com/Surfice/)
**Example**
```java
// A service which receives string events and echoes them.
public class EchoService extends AbstractService
{
protected void onStart() {
System.out.println("Service started");
}
protected void onEvent(String event) {
// This occurs in the context of the service, not the thread that added the event.
System.out.println(event);
}
protected void onExecute() {
System.out.println("Service execute");
}
protected void onPause() {
System.out.println("Service paused");
}
protected void onResume() {
System.out.println("Service resumed");
}
protected void onStop() {
System.out.println("Service stopped");
}
}
// Create the service
EchoService service = new EchoService();
// Restrict the number of events it can process before it automatically stops.
service.setRemainingEvents(5);
// Start the service and add the event
service.start();
service.addEvent("Hello World");
// Request the service to pause and wait until it has paused
service.pause();
// Finally resume the service once it has paused.
service.resume();
// Stop the service now.
service.stop();
// Restart the service and stop it again.
service.start();
service.stop();
```
**Builds**
- [surfice-1.0.0.jar](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Surfice/blob/master/build/surfice-1.0.0.jar?raw=true)
- [surfice-src-1.0.0.jar](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Surfice/blob/master/build/surfice-src-1.0.0.jar?raw=true) *- includes source code*
- [surfice-all-1.0.0.jar](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Surfice/blob/master/build/surfice-1.0.0.jar?raw=true) *- includes all dependencies*
- [surfice-all-src-1.0.0.jar](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Surfice/blob/master/build/surfice-src-1.0.0.jar?raw=true) *- includes all dependencies and source code*
**Projects using surfice:**
- [taskaroo](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Taskaroo)
- [statastic](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Statastic)
- [falcon](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Falcon)
**Dependencies**
- [curity](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Curity)
- [testility](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Testility) *for unit tests*
**Testing Examples**
- [Testing/org/magnos/service](http://gh.magnos.org/?r=https://github.com/ClickerMonkey/Surfice/tree/master/Testing/org/magnos/service)