
cocaine.Service Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cocaine-core Show documentation
Show all versions of cocaine-core Show documentation
Core classes for Cocaine Application Engine.
package cocaine;
import java.io.IOException;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import cocaine.netty.ServiceMessageHandler;
import com.google.common.base.Joiner;
import com.google.common.base.Supplier;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import org.apache.log4j.Logger;
import org.msgpack.MessagePackable;
import org.msgpack.packer.Packer;
import org.msgpack.unpacker.Unpacker;
import rx.Observable;
/**
* @author Anton Bobukh
*/
public class Service {
private static final Logger logger = Logger.getLogger(Service.class);
private final String name;
private final ServiceApi api;
private final Sessions sessions;
private Channel channel;
private Service(String name, ServiceApi api, Bootstrap bootstrap, Supplier endpoint) {
this.name = name;
this.sessions = new Sessions(name);
this.api = api;
connect(bootstrap, endpoint, new ServiceMessageHandler(name, sessions));
}
public static Service create(String name, Bootstrap bootstrap, Supplier endpoint, ServiceApi api) {
return new Service(name, api, bootstrap, endpoint);
}
public Observable invoke(String method, Object... args) {
return invoke(method, Arrays.asList(args));
}
public Observable invoke(String method, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy