Package com.nokia.dempsy.messagetransport

Examples of com.nokia.dempsy.messagetransport.Sender


         boolean justGetOut = false;
         while(keepGoing.get() && !justGetOut)
         {
            try
            {
               Sender sender = senderFactory.getSender(destination);
               sender.send( ("Hello from " + threadInstance).getBytes());
               sentMessageCount.incrementAndGet();
            }
            catch(MessageTransportException e)
            {
               sendFailed.set(true);
View Full Code Here


               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               byte[] messageBytes = "Hello".getBytes();
               Sender sender = factory.getSender(destination);
              
               assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender)sender).getBatchOutgoingMessagesDelayMillis());
              
               sender.send(messageBytes);
               sender.send(messageBytes);
              
               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2;)
                  Thread.sleep(1);
View Full Code Here

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
               sender.send("Hello".getBytes());
              
               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() == 0;)
                  Thread.sleep(1);
View Full Code Here

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
              
               // send messageBytes
               byte[] messageBytes = "Hello".getBytes();
               int sentBytesPerMessage = messageBytes.length + tcpTransportHeaderSize;
              
               sender.send(messageBytes);
               Thread.sleep(batchOutgoingMessagesDelayMillis * 2);
               sender.send(messageBytes);
               sender.send(messageBytes);
               Thread.sleep(batchOutgoingMessagesDelayMillis * 2);
               sender.send(messageBytes);
              
               // now numBytesLastFlush should be set to the num of bytes that were last flushed.
               // numBytesSent should be the total bytes, even those still in the buffer.
               // Therefore numBytesSent - numBytesLastFlush should be the number of bytes waiting.
               // These are asserted below.
View Full Code Here

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
              
               int mtu = ((TcpSender)sender).getMtu();
              
               // send enough messages to get one through
               byte[] messageBytes = "Hello".getBytes();
               int numMessagesSent = 0;
               int numBytesSent = 0;
               int numBytesLastFlush = 0;
               while (numBytesSent < mtu)
               {
                  sender.send(messageBytes);
                  numBytesLastFlush = numBytesSent;
                  numBytesSent += messageBytes.length + tcpTransportHeaderSize;
                  numMessagesSent++;
               }
              
View Full Code Here

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination
               Destination destination2 = adaptor2.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
               factory.getSender(destination2)// create a second sender to make sure the historgram acts correctly
              
               int mtu = ((TcpSender)sender).getMtu();
              
               // now create a message larger than the mtu by 10%
               Random random = new Random();
               byte[] messageBytes = new byte[(int)(mtu * 1.1)];
               for (int i = 0; i < messageBytes.length; i++)
                  messageBytes[i] = (byte)charSet.charAt(random.nextInt(charSet.length()));
              
               // send the message ... it should be sent without delay.
               sender.send(messageBytes);

               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() == 0;)
                  Thread.sleep(1);
View Full Code Here

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
              
               int mtu = ((TcpSender)sender).getMtu();
              
               // now create a message larger than the mtu by 10%
               Random random = new Random();
               byte[] largeMessageBytes = new byte[(int)(mtu * 1.1)];
               for (int i = 0; i < largeMessageBytes.length; i++)
                  largeMessageBytes[i] = (byte)charSet.charAt(random.nextInt(charSet.length()));
              
               byte[] messageBytes = "Hello".getBytes();
              
               // send the message ... it should be sent without delay.
               sender.send(largeMessageBytes); // this should flush everything
               sender.send(messageBytes); // this should wait for another message.
               sender.send(messageBytes); // this should wait for another message.
               sender.send(largeMessageBytes); // this should flush everything

               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() < 4;)
                  Thread.sleep(1);
View Full Code Here

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               final Sender sender = factory.getSender(destination);
              
               final int numAdaptorThreads = adaptor.executor.getNumThreads();
              
               assertTrue(numAdaptorThreads > 1);

               DefaultDempsyExecutor executor = ((DefaultDempsyExecutor)adaptor.executor);
              
               // first dump the max number of messages
               for (int i = 0; i < executor.getMaxNumberOfQueuedLimitedTasks(); i++)
                  sender.send("Hello".getBytes());
              
               // wait until there's room in the queue due to messages being passed on to
               // the receiver; one for each thread.
               assertTrue(TestUtils.poll(baseTimeoutMillis, receiver, new TestUtils.Condition<StringListener>()
                     { @Override public boolean conditionMet(StringListener o) { return o.numIn.get() == numAdaptorThreads; } }));
              
               // send one more for each opened up place in the queue now
               for (int i = 0; i < numAdaptorThreads; i++)
                  sender.send("Hello".getBytes());
              
               // wait until all Listeners are in and all threads enqueued. This is the totally full state.
               assertTrue(TestUtils.poll(baseTimeoutMillis, ((DefaultDempsyExecutor)adaptor.executor), new TestUtils.Condition<DefaultDempsyExecutor>()
                     { @Override public boolean conditionMet(DefaultDempsyExecutor o) { return o.getNumberLimitedPending() == o.getMaxNumberOfQueuedLimitedTasks(); } }));

               assertEquals(0,statsCollector.getDiscardedMessageCount());
              
               // we are going to poll but we are going to keep adding to the queu of tasks. So we add 2, let one go,
               //  until we start seeing rejects.

               assertTrue(TestUtils.poll(baseTimeoutMillis, statsCollector,
                     new TestUtils.Condition<BasicStatsCollector>() {
                  @Override public boolean conditionMet(BasicStatsCollector o) throws Throwable
                  {
                     sender.send("Hello".getBytes());
                     sender.send("Hello".getBytes());
                    
                     synchronized(latch)
                     {
                        latch.notify(); // single exit.
                     }
View Full Code Here

       * Returns whether or not the message was actually sent. Doesn't touch the statsCollector
       */
      public boolean route(Object key, Object message)
      {
         boolean messageFailed = true;
         Sender sender = null;
         try
         {
            Destination destination = strategyOutbound.selectDestinationForMessage(key, message);

            if (destination == null)
            {
               if (logger.isInfoEnabled())
                  logger.info("Couldn't find a destination for " + SafeString.objectDescription(message));
               if (statsCollector != null) statsCollector.messageNotSent();
               return false;
            }

            sender = senderFactory.getSender(destination);
            if (sender == null)
               logger.error("Couldn't figure out a means to send " + SafeString.objectDescription(message) +
                     " to " + SafeString.valueOf(destination) + "");
            else
            {
               byte[] data = serializer.serialize(message);
               sender.send(data); // the sender is assumed to increment the stats collector.
               messageFailed = false;
            }
         }
         catch(DempsyException e)
         {
View Full Code Here

   {

      ctx = new ClassPathXmlApplicationContext(applicationContextFilename, getClass());
      ctx.registerShutdownHook();       
     
      Sender lsender = (Sender)ctx.getBean("sender");
      sender = lsender;
     
      pojo = (MyPojo)ctx.getBean("testPojo");
      overflowHandler = (MyOverflowHandler)ctx.getBean("testOverflowHandler");
   }
View Full Code Here

TOP

Related Classes of com.nokia.dempsy.messagetransport.Sender

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.