Search in sources :

Example 11 with Cancellable

use of com.continuuity.weave.common.Cancellable in project weave by continuuity.

the class SocketServer method initialize.

@Override
public void initialize(WeaveContext context) {
    super.initialize(context);
    running = true;
    try {
        serverSocket = new ServerSocket(0);
        LOG.info("Server started: " + serverSocket.getLocalSocketAddress() + ", id: " + context.getInstanceId() + ", count: " + context.getInstanceCount());
        final List<Cancellable> cancellables = ImmutableList.of(context.announce(context.getApplicationArguments()[0], serverSocket.getLocalPort()), context.announce(context.getArguments()[0], serverSocket.getLocalPort()));
        canceller = new Cancellable() {

            @Override
            public void cancel() {
                for (Cancellable c : cancellables) {
                    c.cancel();
                }
            }
        };
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Cancellable(com.continuuity.weave.common.Cancellable) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Aggregations

Cancellable (com.continuuity.weave.common.Cancellable)11 Map (java.util.Map)6 Test (org.junit.Test)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 SettableOperationFuture (com.continuuity.weave.internal.zookeeper.SettableOperationFuture)2 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 Watcher (org.apache.zookeeper.Watcher)2 RunId (com.continuuity.weave.api.RunId)1 ProcessController (com.continuuity.weave.internal.ProcessController)1 NodeChildren (com.continuuity.weave.zookeeper.NodeChildren)1 ZKClientService (com.continuuity.weave.zookeeper.ZKClientService)1 ZKOperations (com.continuuity.weave.zookeeper.ZKOperations)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 Set (java.util.Set)1 Executor (java.util.concurrent.Executor)1