Package eu.mosaic_cloud.tools.threading.implementations.basic

Examples of eu.mosaic_cloud.tools.threading.implementations.basic.BasicThreadingContext$BasicThreadFactory


    final Transcript transcript = Transcript.create (this);
    BasicThreadingSecurityManager.initialize ();
    final Pipe pipe = Pipe.open ();
    final QueueingExceptionTracer exceptionsQueue = QueueingExceptionTracer.create (NullExceptionTracer.defaultInstance);
    final TranscriptExceptionTracer exceptions = TranscriptExceptionTracer.create (transcript, exceptionsQueue);
    final BasicThreadingContext threading = BasicThreadingContext.create (this, exceptions, exceptions.catcher);
    Assert.assertTrue (threading.initialize (BasicChannelTest.defaultPollTimeout));
    final BasicCallbackReactor reactor = BasicCallbackReactor.create (threading, exceptions);
    Assert.assertTrue (reactor.initialize (BasicChannelTest.defaultPollTimeout));
    final DefaultChannelMessageCoder coder = DefaultChannelMessageCoder.defaultInstance;
    final BasicChannel channel = BasicChannel.create (pipe.source (), pipe.sink (), coder, reactor, threading, exceptions);
    Assert.assertTrue (channel.initialize (BasicChannelTest.defaultPollTimeout));
    final ChannelController channelController = channel.getController ();
    final ChannelCallbacks channelCallbacksProxy = reactor.createProxy (ChannelCallbacks.class);
    Assert.assertTrue (channelController.bind (channelCallbacksProxy).await (BasicChannelTest.defaultPollTimeout));
    final QueueingChannelCallbacks channelCallbacks = QueueingChannelCallbacks.create (channelController, exceptions);
    final CallbackIsolate channelCallbacksIsolate = reactor.createIsolate ();
    Assert.assertTrue (reactor.assignHandler (channelCallbacksProxy, channelCallbacks, channelCallbacksIsolate).await (BasicChannelTest.defaultPollTimeout));
    for (int index = 0; index < BasicChannelTest.defaultTries; index++) {
      final ChannelMessage outboundMessage = RandomMessageGenerator.defaultInstance.generateChannelMessage ();
      Assert.assertTrue (channelController.send (outboundMessage).await (BasicChannelTest.defaultPollTimeout));
      final ChannelMessage inboundMessage = channelCallbacks.queue.poll (BasicChannelTest.defaultPollTimeout, TimeUnit.MILLISECONDS);
      Assert.assertNotNull (inboundMessage);
      Assert.assertEquals (outboundMessage.metaData, inboundMessage.metaData);
      Assert.assertEquals (outboundMessage.data, inboundMessage.data);
    }
    pipe.sink ().close ();
    Assert.assertTrue (channel.destroy (BasicChannelTest.defaultPollTimeout));
    Assert.assertTrue (channelCallbacksIsolate.destroy ().await (BasicChannelTest.defaultPollTimeout));
    Assert.assertTrue (reactor.destroy (BasicChannelTest.defaultPollTimeout));
    Assert.assertTrue (threading.destroy (BasicChannelTest.defaultPollTimeout));
    Assert.assertNull (exceptionsQueue.queue.poll ());
  }
View Full Code Here


    final Transcript transcript = Transcript.create (this);
    BasicThreadingSecurityManager.initialize ();
    final Pipe pipe = Pipe.open ();
    final QueueingExceptionTracer exceptionsQueue = QueueingExceptionTracer.create (NullExceptionTracer.defaultInstance);
    final TranscriptExceptionTracer exceptions = TranscriptExceptionTracer.create (transcript, exceptionsQueue);
    final BasicThreadingContext threading = BasicThreadingContext.create (this, exceptions, exceptions.catcher);
    Assert.assertTrue (threading.initialize (BasicComponentTest.defaultPollTimeout));
    final BasicCallbackReactor reactor = BasicCallbackReactor.create (threading, exceptions);
    Assert.assertTrue (reactor.initialize (BasicComponentTest.defaultPollTimeout));
    final DefaultChannelMessageCoder coder = DefaultChannelMessageCoder.defaultInstance;
    final BasicChannel channel = BasicChannel.create (pipe.source (), pipe.sink (), coder, reactor, threading, exceptions);
    final BasicComponent component = BasicComponent.create (reactor, exceptions);
    Assert.assertTrue (channel.initialize (BasicComponentTest.defaultPollTimeout));
    Assert.assertTrue (component.initialize (BasicComponentTest.defaultPollTimeout));
    final ComponentController componentController = component.getController ();
    final ComponentCallbacks componentCallbacksProxy = reactor.createProxy (ComponentCallbacks.class);
    Assert.assertTrue (componentController.bind (componentCallbacksProxy, channel.getController ()).await (BasicComponentTest.defaultPollTimeout));
    final QueueingComponentCallbacks componentCallbacks = QueueingComponentCallbacks.create (componentController, exceptions);
    final CallbackIsolate componentCallbacksIsolate = reactor.createIsolate ();
    Assert.assertTrue (reactor.assignHandler (componentCallbacksProxy, componentCallbacks, componentCallbacksIsolate).await (BasicComponentTest.defaultPollTimeout));
    final ComponentIdentifier peer = ComponentIdentifier.resolve (Strings.repeat ("00", 20));
    for (int index = 0; index < BasicComponentTest.defaultTries; index++) {
      final ComponentCallRequest outboundRequest = RandomMessageGenerator.defaultInstance.generateComponentCallRequest ();
      Assert.assertTrue (componentController.call (peer, outboundRequest).await (BasicComponentTest.defaultPollTimeout));
      final ComponentCallRequest inboundRequest = (ComponentCallRequest) componentCallbacks.queue.poll (BasicComponentTest.defaultPollTimeout, TimeUnit.MILLISECONDS);
      Assert.assertNotNull (inboundRequest);
      Assert.assertEquals (outboundRequest.operation, inboundRequest.operation);
      Assert.assertEquals (outboundRequest.inputs, inboundRequest.inputs);
      Assert.assertEquals (outboundRequest.data, inboundRequest.data);
      final ComponentCallReply outboundReply = RandomMessageGenerator.defaultInstance.generateComponentCallReply (inboundRequest);
      Assert.assertTrue (componentController.callReturn (outboundReply).await (BasicComponentTest.defaultPollTimeout));
      final ComponentCallReply inboundReply = (ComponentCallReply) componentCallbacks.queue.poll (BasicComponentTest.defaultPollTimeout, TimeUnit.MILLISECONDS);
      Assert.assertNotNull (inboundReply);
      Assert.assertEquals (outboundRequest.reference, inboundReply.reference);
      Assert.assertEquals (outboundRequest.inputs, inboundReply.outputsOrError);
      Assert.assertEquals (outboundRequest.data, inboundReply.data);
    }
    pipe.sink ().close ();
    Assert.assertTrue (component.await (BasicComponentTest.defaultPollTimeout * 10));
    Assert.assertTrue (component.destroy (BasicComponentTest.defaultPollTimeout));
    Assert.assertTrue (channel.destroy (BasicComponentTest.defaultPollTimeout));
    Assert.assertTrue (componentCallbacksIsolate.destroy ().await (BasicComponentTest.defaultPollTimeout));
    Assert.assertTrue (reactor.destroy (BasicComponentTest.defaultPollTimeout));
    Assert.assertTrue (threading.destroy (BasicComponentTest.defaultPollTimeout));
    Assert.assertNull (exceptionsQueue.queue.poll ());
  }
View Full Code Here

  {
    final Transcript transcript = Transcript.create (this);
    BasicThreadingSecurityManager.initialize ();
    final QueueingExceptionTracer exceptionsQueue = QueueingExceptionTracer.create (NullExceptionTracer.defaultInstance);
    final TranscriptExceptionTracer exceptions = TranscriptExceptionTracer.create (transcript, exceptionsQueue);
    final BasicThreadingContext threading = BasicThreadingContext.create (this, exceptions, exceptions.catcher);
    Assert.assertTrue (threading.initialize (KvTest.defaultPollTimeout));
    final String serverIdentity = UUID.randomUUID ().toString ();
    final String clientIdentity = UUID.randomUUID ().toString ();
    final ZeroMqChannel serverChannel = ZeroMqChannel.create (serverIdentity, threading, exceptions);
    serverChannel.register (KvSession.Server);
    serverChannel.accept (KvTest.defaultServerEndpoint);
    final ZeroMqChannel clientChannel = ZeroMqChannel.create (clientIdentity, threading, exceptions);
    clientChannel.register (KvSession.Client);
    clientChannel.connect (KvTest.defaultServerEndpoint);
    final KvServer server = new KvServer (exceptions, KvTest.defaultPollTimeout);
    server.initialize (serverChannel);
    final KvClient client_1 = new KvClient ();
    Assert.assertEquals (Boolean.TRUE, Threading.awaitOrCatch (client_1.initialize (clientChannel, serverIdentity), KvTest.defaultPollTimeout));
    Assert.assertEquals (Boolean.TRUE, Threading.awaitOrCatch (client_1.put ("a", "1"), KvTest.defaultPollTimeout));
    Assert.assertEquals (Boolean.TRUE, Threading.awaitOrCatch (client_1.put ("b", "2"), KvTest.defaultPollTimeout));
    final KvClient client_2 = new KvClient ();
    Assert.assertEquals (Boolean.TRUE, Threading.awaitOrCatch (client_2.initialize (clientChannel, serverIdentity), KvTest.defaultPollTimeout));
    Assert.assertEquals ("1", Threading.awaitOrCatch (client_2.get ("a"), KvTest.defaultPollTimeout));
    Assert.assertEquals ("2", Threading.awaitOrCatch (client_2.get ("b"), KvTest.defaultPollTimeout));
    Assert.assertTrue (serverChannel.terminate (KvTest.defaultPollTimeout));
    Assert.assertTrue (clientChannel.terminate (KvTest.defaultPollTimeout));
    Assert.assertTrue (threading.destroy (KvTest.defaultPollTimeout));
    Assert.assertNull (exceptionsQueue.queue.poll ());
  }
View Full Code Here

    else
      classLoader = classLoader_;
    final ThreadingContext threading;
    if (threading_ == null) {
      transcript.traceDebugging ("creating threading context...");
      final BasicThreadingContext threading1 = BasicThreadingContext.create (BasicComponentHarnessMain.class, exceptions, UncaughtExceptionHandler.create (exceptions), classLoader);
      transcript.traceDebugging ("initializing threading context...");
      threading1.initialize ();
      threading = threading1;
    } else
      threading = threading_;
    final BasicCallbackReactor reactor;
    {
View Full Code Here

    BasicThreadingSecurityManager.initialize ();
    final Pipe pipe1 = Pipe.open ();
    final Pipe pipe2 = Pipe.open ();
    final QueueingExceptionTracer exceptionsQueue = QueueingExceptionTracer.create (NullExceptionTracer.defaultInstance);
    final TranscriptExceptionTracer exceptions = TranscriptExceptionTracer.create (transcript, exceptionsQueue);
    final BasicThreadingContext threading = BasicThreadingContext.create (this, exceptions, exceptions.catcher);
    Assert.assertTrue (threading.initialize (AbacusTest.defaultPollTimeout));
    final BasicCallbackReactor reactor = BasicCallbackReactor.create (threading, exceptions);
    Assert.assertTrue (reactor.initialize (AbacusTest.defaultPollTimeout));
    final DefaultChannelMessageCoder coder = DefaultChannelMessageCoder.defaultInstance;
    final BasicChannel serverChannel = BasicChannel.create (pipe1.source (), pipe2.sink (), coder, reactor, threading, exceptions);
    final BasicChannel clientChannel = BasicChannel.create (pipe2.source (), pipe1.sink (), coder, reactor, threading, exceptions);
    final BasicComponent serverComponent = BasicComponent.create (reactor, exceptions);
    final BasicComponent clientComponent = BasicComponent.create (reactor, exceptions);
    Assert.assertTrue (serverChannel.initialize (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientChannel.initialize (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (serverComponent.initialize (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientComponent.initialize (AbacusTest.defaultPollTimeout));
    final ComponentController serverComponentController = serverComponent.getController ();
    final ComponentController clientComponentController = clientComponent.getController ();
    final ComponentCallbacks serverComponentCallbacksProxy = reactor.createProxy (ComponentCallbacks.class);
    final ComponentCallbacks clientComponentCallbacksProxy = reactor.createProxy (ComponentCallbacks.class);
    Assert.assertTrue (serverComponentController.bind (serverComponentCallbacksProxy, serverChannel.getController ()).await (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientComponentController.bind (clientComponentCallbacksProxy, clientChannel.getController ()).await (AbacusTest.defaultPollTimeout));
    final AbacusComponentCallbacks serverComponentCallbacks = new AbacusComponentCallbacks (ComponentEnvironment.create (ComponentIdentifier.standalone, this.getClass ().getClassLoader (), reactor, threading, exceptions));
    final QueueingComponentCallbacks clientComponentCallbacks = QueueingComponentCallbacks.create (clientComponentController, exceptions);
    final CallbackIsolate serverComponentCallbacksIsolate = reactor.createIsolate ();
    final CallbackIsolate clientComponentCallbacksIsolate = reactor.createIsolate ();
    Assert.assertTrue (reactor.assignHandler (serverComponentCallbacksProxy, serverComponentCallbacks, serverComponentCallbacksIsolate).await (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (reactor.assignHandler (clientComponentCallbacksProxy, clientComponentCallbacks, clientComponentCallbacksIsolate).await (AbacusTest.defaultPollTimeout));
    final ComponentIdentifier peer = ComponentIdentifier.resolve (Strings.repeat ("00", 20));
    for (int index = 0; index < AbacusTest.defaultTries; index++) {
      final double operandA = (int) (Math.random () * 10);
      final double operandB = (int) (Math.random () * 10);
      final ComponentCallRequest request = ComponentCallRequest.create ("+", Arrays.asList (Double.valueOf (operandA), Double.valueOf (operandB)), ByteBuffer.allocate (0), ComponentCallReference.create ());
      Assert.assertTrue (clientComponentController.call (peer, request).await (AbacusTest.defaultPollTimeout));
      final ComponentCallReply reply = (ComponentCallReply) clientComponentCallbacks.queue.poll (AbacusTest.defaultPollTimeout, TimeUnit.MILLISECONDS);
      Assert.assertNotNull (reply);
      Assert.assertTrue (reply.ok);
      Assert.assertNotNull (reply.outputsOrError);
      Assert.assertEquals (request.reference, reply.reference);
      Assert.assertTrue ((operandA + operandB) == ((Number) reply.outputsOrError).doubleValue ());
    }
    pipe1.sink ().close ();
    pipe2.sink ().close ();
    Assert.assertTrue (serverComponent.await (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientComponent.await (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (serverComponent.destroy (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientComponent.destroy (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (serverChannel.destroy (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientChannel.destroy (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (serverComponentCallbacksIsolate.destroy ().await (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (clientComponentCallbacksIsolate.destroy ().await (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (reactor.destroy (AbacusTest.defaultPollTimeout));
    Assert.assertTrue (threading.destroy (AbacusTest.defaultPollTimeout));
    Assert.assertNull (exceptionsQueue.queue.poll ());
  }
View Full Code Here

    Preconditions.checkNotNull (componentCallbacks);
    Preconditions.checkNotNull (componentConfiguration);
    BasicThreadingSecurityManager.initialize ();
    final BaseExceptionTracer exceptions = AbortingExceptionTracer.defaultInstance;
    final ClassLoader classLoader = ClassLoader.getSystemClassLoader ();
    final BasicThreadingContext threading = BasicThreadingContext.create (BasicComponentHarnessMain.class, exceptions, exceptions.catcher, classLoader);
    threading.initialize ();
    BasicComponentLocalLauncher.launch (controllerBaseUrl, channelAddress, componentCallbacks, componentConfiguration, classLoader, threading, exceptions);
    threading.destroy ();
  }
View Full Code Here

  {
    Preconditions.checkNotNull (arguments);
    BasicThreadingSecurityManager.initialize ();
    final BaseExceptionTracer exceptions = AbortingExceptionTracer.defaultInstance;
    final ClassLoader classLoader = ClassLoader.getSystemClassLoader ();
    final BasicThreadingContext threading = BasicThreadingContext.create (BasicComponentHarnessMain.class, exceptions, exceptions.catcher, classLoader);
    threading.initialize ();
    BasicComponentLauncherMain.main (arguments, classLoader, threading, exceptions);
    threading.destroy ();
  }
View Full Code Here

  {
    final Transcript transcript = Transcript.create (this);
    BasicThreadingSecurityManager.initialize ();
    final QueueingExceptionTracer exceptionsQueue = QueueingExceptionTracer.create (NullExceptionTracer.defaultInstance);
    final TranscriptExceptionTracer exceptions = TranscriptExceptionTracer.create (transcript, exceptionsQueue);
    final BasicThreadingContext threading = BasicThreadingContext.create (this, exceptions, exceptions.catcher);
    Assert.assertTrue (threading.initialize (ZeroMqChannelTest.defaultPollTimeout));
    final String serverIdentifier = UUID.randomUUID ().toString ();
    final String clientIdentifier = UUID.randomUUID ().toString ();
    final ZeroMqChannelSocket server = ZeroMqChannelSocket.create (serverIdentifier, null, threading, exceptions);
    final ZeroMqChannelSocket client = ZeroMqChannelSocket.create (clientIdentifier, null, threading, exceptions);
    server.accept (ZeroMqChannelTest.defaultServerEndpoint);
    client.connect (ZeroMqChannelTest.defaultServerEndpoint);
    for (int index = 0; index < ZeroMqChannelTest.defaultTries; index++) {
      final ByteBuffer header = ByteBuffer.wrap (UUID.randomUUID ().toString ().getBytes ());
      final ByteBuffer payload = ByteBuffer.wrap (UUID.randomUUID ().toString ().getBytes ());
      final ZeroMqChannelPacket packet1 = ZeroMqChannelPacket.create (serverIdentifier, header, payload);
      client.enqueue (packet1, ZeroMqChannelTest.defaultPollTimeout);
      final ZeroMqChannelPacket packet2 = server.dequeue (ZeroMqChannelTest.defaultPollTimeout);
      Assert.assertNotNull (packet2);
      server.enqueue (packet2, ZeroMqChannelTest.defaultPollTimeout);
      final ZeroMqChannelPacket packet3 = client.dequeue (ZeroMqChannelTest.defaultPollTimeout);
      Assert.assertNotNull (packet3);
      packet1.header.flip ();
      packet1.payload.flip ();
      Assert.assertEquals (packet1.header, packet3.header);
      Assert.assertEquals (packet1.payload, packet3.payload);
    }
    Assert.assertTrue (server.terminate (ZeroMqChannelTest.defaultPollTimeout));
    Assert.assertTrue (client.terminate (ZeroMqChannelTest.defaultPollTimeout));
    Assert.assertTrue (threading.destroy (ZeroMqChannelTest.defaultPollTimeout));
    Assert.assertNull (exceptionsQueue.queue.poll ());
  }
View Full Code Here

  {
    final Transcript transcript = Transcript.create (this);
    BasicThreadingSecurityManager.initialize ();
    final QueueingExceptionTracer exceptionsQueue = QueueingExceptionTracer.create (NullExceptionTracer.defaultInstance);
    final TranscriptExceptionTracer exceptions = TranscriptExceptionTracer.create (transcript, exceptionsQueue);
    final BasicThreadingContext threading = BasicThreadingContext.create (this, exceptions, exceptions.catcher);
    Assert.assertTrue (threading.initialize (BasicCallbackReactorTest.defaultPollTimeout));
    final BasicCallbackReactor reactor = BasicCallbackReactor.create (threading, exceptions);
    Assert.assertTrue (reactor.initialize (BasicCallbackReactorTest.defaultPollTimeout));
    final CallbackIsolate isolate = reactor.createIsolate ();
    Assert.assertNotNull (isolate);
    final LinkedList<QueueCallbacks<Integer>> triggers = new LinkedList<QueueCallbacks<Integer>> ();
    for (int index = 0; index < BasicCallbackReactorTest.defaultQueueCount; index++) {
      final QueueCallbacks<Integer> proxy = reactor.createProxy (QueueCallbacks.class);
      triggers.add (proxy);
    }
    final LinkedList<CallbackCompletion<Void>> completions = new LinkedList<CallbackCompletion<Void>> ();
    {
      int counter = 0;
      for (int index = 0; index < BasicCallbackReactorTest.defaultCallCount; index++) {
        for (final QueueCallbacks<Integer> trigger : triggers) {
          final CallbackCompletion<Void> completion = trigger.enqueue (Integer.valueOf (counter));
          completions.add (completion);
          counter++;
        }
      }
    }
    final LinkedList<QueueingQueueCallbackHandler<Integer>> handlers = new LinkedList<QueueingQueueCallbackHandler<Integer>> ();
    for (int index = 0; index < BasicCallbackReactorTest.defaultQueueCount; index++) {
      final QueueingQueueCallbackHandler<Integer> handler = QueueingQueueCallbackHandler.create (exceptions);
      final CallbackCompletion<Void> completion = reactor.assignHandler (triggers.get (index), handler, isolate);
      handlers.add (handler);
      completions.add (completion);
    }
    for (final CallbackCompletion<Void> completion : completions)
      Assert.assertTrue (completion.await (BasicCallbackReactorTest.defaultPollTimeout));
    {
      int counter = 0;
      for (int index = 0; index < BasicCallbackReactorTest.defaultCallCount; index++)
        for (final QueueingQueueCallbackHandler<Integer> handler : handlers) {
          Assert.assertEquals (Integer.valueOf (counter), handler.queue.poll ());
          counter++;
        }
      for (final QueueingQueueCallbackHandler<Integer> handler : handlers)
        Assert.assertNull (handler.queue.poll ());
    }
    Assert.assertTrue (isolate.destroy ().await (BasicCallbackReactorTest.defaultPollTimeout));
    Assert.assertTrue (reactor.destroy (BasicCallbackReactorTest.defaultPollTimeout));
    Assert.assertTrue (threading.destroy (BasicCallbackReactorTest.defaultPollTimeout));
    Assert.assertNull (exceptionsQueue.queue.poll ());
  }
View Full Code Here

TOP

Related Classes of eu.mosaic_cloud.tools.threading.implementations.basic.BasicThreadingContext$BasicThreadFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.