Package eu.mosaic_cloud.tools.callbacks.implementations.basic

Examples of eu.mosaic_cloud.tools.callbacks.implementations.basic.BasicCallbackReactor$ActorAssignAction


    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 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

      transcript.traceDebugging ("initializing threading context...");
      threading1.initialize ();
      threading = threading1;
    } else
      threading = threading_;
    final BasicCallbackReactor reactor;
    {
      transcript.traceDebugging ("creating callbacks reactor...");
      reactor = BasicCallbackReactor.create (threading, exceptions);
      transcript.traceDebugging ("initializing callbacks reactor....");
      reactor.initialize ();
    }
    final Environment environment = new Environment (identifier, classLoader, reactor, threading, transcript, exceptions, options);
    return (environment);
  }
View Full Code Here

    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

    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.callbacks.implementations.basic.BasicCallbackReactor$ActorAssignAction

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.