Search in sources :

Example 6 with Server

use of com.datatorrent.bufferserver.server.Server in project apex-core by apache.

the class DiskStorageTest method setupServerAndClients.

@BeforeClass
public static void setupServerAndClients() throws Exception {
    eventloopServer = DefaultEventLoop.createEventLoop("server");
    eventloopServer.start();
    eventloopClient = DefaultEventLoop.createEventLoop("client");
    eventloopClient.start();
    instance = new Server(eventloopServer, 0, 1024, 8);
    instance.setSpoolStorage(new DiskStorage());
    address = instance.run();
    assertFalse(address.isUnresolved());
    bsp = new Publisher("MyPublisher");
    eventloopClient.connect(address, bsp);
    bss = new Subscriber("MySubscriber");
    eventloopClient.connect(address, bss);
    bsc = new Controller("MyPublisher");
    eventloopClient.connect(address, bsc);
}
Also used : Server(com.datatorrent.bufferserver.server.Server) Subscriber(com.datatorrent.bufferserver.support.Subscriber) Publisher(com.datatorrent.bufferserver.support.Publisher) Controller(com.datatorrent.bufferserver.support.Controller) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with Server

use of com.datatorrent.bufferserver.server.Server in project apex-core by apache.

the class StreamingContainer method setup.

@SuppressWarnings("unchecked")
public void setup(StreamingContainerContext ctx) {
    containerContext = ctx;
    /* add a request factory local to this container */
    this.requestFactory = new RequestFactory();
    ctx.attributes.put(ContainerContext.REQUEST_FACTORY, requestFactory);
    heartbeatIntervalMillis = ctx.getValue(Context.DAGContext.HEARTBEAT_INTERVAL_MILLIS);
    firstWindowMillis = ctx.startWindowMillis;
    windowWidthMillis = ctx.getValue(Context.DAGContext.STREAMING_WINDOW_SIZE_MILLIS);
    checkpointWindowCount = ctx.getValue(Context.DAGContext.CHECKPOINT_WINDOW_COUNT);
    fastPublisherSubscriber = ctx.getValue(LogicalPlan.FAST_PUBLISHER_SUBSCRIBER);
    Map<Class<?>, Class<? extends StringCodec<?>>> codecs = ctx.getValue(Context.DAGContext.STRING_CODECS);
    StringCodecs.loadConverters(codecs);
    try {
        if (ctx.deployBufferServer) {
            eventloop.start();
            int bufferServerRAM = ctx.getValue(ContainerContext.BUFFER_SERVER_MB);
            logger.debug("buffer server memory {}", bufferServerRAM);
            int blockCount;
            int blocksize;
            if (bufferServerRAM < ContainerContext.BUFFER_SERVER_MB.defaultValue) {
                blockCount = 8;
                blocksize = bufferServerRAM / blockCount;
                if (blocksize < 1) {
                    blocksize = 1;
                }
            } else {
                blocksize = 64;
                blockCount = bufferServerRAM / blocksize;
            }
            // start buffer server, if it was not set externally
            bufferServer = new Server(eventloop, 0, blocksize * 1024 * 1024, blockCount);
            bufferServer.setAuthToken(ctx.getValue(StreamingContainerContext.BUFFER_SERVER_TOKEN));
            if (ctx.getValue(Context.DAGContext.BUFFER_SPOOLING)) {
                bufferServer.setSpoolStorage(new DiskStorage());
            }
            bufferServerAddress = NetUtils.getConnectAddress(bufferServer.run());
            logger.debug("Buffer server started: {}", bufferServerAddress);
        }
    } catch (IOException ex) {
        logger.warn("deploy request failed due to {}", ex);
        throw new IllegalStateException("Failed to deploy buffer server", ex);
    }
    for (Class<?> clazz : ContainerEvent.CONTAINER_EVENTS_LISTENERS) {
        try {
            Object newInstance = clazz.newInstance();
            singletons.put(clazz.getName(), newInstance);
            if (newInstance instanceof Component) {
                components.add((Component<ContainerContext>) newInstance);
            }
            eventBus.subscribe(newInstance);
        } catch (InstantiationException ex) {
            logger.warn("Container Event Listener Instantiation", ex);
        } catch (IllegalAccessException ex) {
            logger.warn("Container Event Listener Instantiation", ex);
        }
    }
    operateListeners(ctx, true);
}
Also used : Server(com.datatorrent.bufferserver.server.Server) IOException(java.io.IOException) Checkpoint(com.datatorrent.stram.api.Checkpoint) ContainerContext(com.datatorrent.stram.api.ContainerContext) StreamingContainerContext(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StreamingContainerContext) StringCodec(com.datatorrent.api.StringCodec) RequestFactory(com.datatorrent.stram.api.RequestFactory) Component(com.datatorrent.api.Component) DiskStorage(com.datatorrent.bufferserver.storage.DiskStorage)

Aggregations

Server (com.datatorrent.bufferserver.server.Server)7 InetSocketAddress (java.net.InetSocketAddress)4 DefaultEventLoop (com.datatorrent.netlet.DefaultEventLoop)3 IOException (java.io.IOException)3 DiskStorage (com.datatorrent.bufferserver.storage.DiskStorage)2 Checkpoint (com.datatorrent.stram.api.Checkpoint)2 BeforeClass (org.junit.BeforeClass)2 BeforeClass (org.testng.annotations.BeforeClass)2 DefaultAttributeMap (com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap)1 Component (com.datatorrent.api.Component)1 Sink (com.datatorrent.api.Sink)1 StringCodec (com.datatorrent.api.StringCodec)1 PayloadTuple (com.datatorrent.bufferserver.packet.PayloadTuple)1 Controller (com.datatorrent.bufferserver.support.Controller)1 Publisher (com.datatorrent.bufferserver.support.Publisher)1 Subscriber (com.datatorrent.bufferserver.support.Subscriber)1 EventLoop (com.datatorrent.netlet.EventLoop)1 CustomControlTupleTest (com.datatorrent.stram.CustomControlTupleTest)1 ContainerStartRequest (com.datatorrent.stram.StreamingContainerAgent.ContainerStartRequest)1 ContainerContext (com.datatorrent.stram.api.ContainerContext)1