Package org.hornetq.spi.core.remoting

Examples of org.hornetq.spi.core.remoting.Connection


         return null;
      synchronized (connectionLock)
      {
      if (connection == null)
      {
         Connection tc = null;

         try
         {
            DelegatingBufferHandler handler = new DelegatingBufferHandler();

            connector = connectorFactory.createConnector(connectorConfig.getParams(),
                                                         handler,
                                                         this,
                                                         closeExecutor,
                                                         threadPool,
                                                         scheduledThreadPool);

            if (HornetQClientLogger.LOGGER.isDebugEnabled())
            {
               HornetQClientLogger.LOGGER.debug("Trying to connect with connector = " + connectorFactory +
                                                  ", parameters = " +
                                                  connectorConfig.getParams() +
                                                  " connector = " +
                                                  connector);
            }

            if (connector != null)
            {
               connector.start();

               if (ClientSessionFactoryImpl.isDebug)
               {
                  HornetQClientLogger.LOGGER.debug("Trying to connect at the main server using connector :" + connectorConfig);
               }

               tc = connector.createConnection();

               if (tc == null)
               {
                  if (ClientSessionFactoryImpl.isDebug)
                  {
                     HornetQClientLogger.LOGGER.debug("Main server is not up. Hopefully there's a backup configured now!");
                  }

                  try
                  {
                     connector.close();
                  }
                  catch (Throwable t)
                  {
                  }

                  connector = null;
               }
            }
            // if connection fails we can try the backup in case it has come live
            if (connector == null)
            {
               if (backupConfig != null)
               {
                  if (ClientSessionFactoryImpl.isDebug)
                  {
                     HornetQClientLogger.LOGGER.debug("Trying backup config = " + backupConfig);
                  }
                  ConnectorFactory backupConnectorFactory = instantiateConnectorFactory(backupConfig.getFactoryClassName());
                  connector = backupConnectorFactory.createConnector(backupConfig.getParams(),
                                                                     handler,
                                                                     this,
                                                                     closeExecutor,
                                                                     threadPool,
                                                                     scheduledThreadPool);
                  if (connector != null)
                  {
                     connector.start();

                     tc = connector.createConnection();

                     if (tc == null)
                     {
                        if (ClientSessionFactoryImpl.isDebug)
                        {
                           HornetQClientLogger.LOGGER.debug("Backup is not active yet");
                        }

                        try
                        {
                           connector.close();
                        }
                        catch (Throwable t)
                        {
                        }

                        connector = null;
                     }
                     else
                     {
                        /*looks like the backup is now live, lets use that*/

                        if (ClientSessionFactoryImpl.isDebug)
                        {
                           HornetQClientLogger.LOGGER.debug("Connected to the backup at " + backupConfig);
                        }

                        connectorConfig = backupConfig;

                        backupConfig = null;

                        connectorFactory = backupConnectorFactory;
                     }
                  }
               }
               else
               {
                  if (ClientSessionFactoryImpl.isTrace)
                  {
                     HornetQClientLogger.LOGGER.trace("No Backup configured!", new Exception("trace"));
                  }
               }
            }
         }
         catch (Exception e)
         {
            // Sanity catch for badly behaved remoting plugins

            HornetQClientLogger.LOGGER.createConnectorException(e);

            if (tc != null)
            {
               try
               {
                  tc.close();
               }
               catch (Throwable t)
               {
               }
            }
View Full Code Here


                     Packet packet = new PacketImpl(PacketImpl.SESS_START);

                     packet.setChannelID(channel.getID());

                     Connection conn = channel.getConnection().getTransportConnection();

                     HornetQBuffer buffer = packet.encode(channel.getConnection());

                     conn.write(buffer, false, false);
                  }

                  resetCreditManager = true;
               }
View Full Code Here

   private void sendPacketWithoutLock(final Packet packet)
   {
      packet.setChannelID(channel.getID());

      Connection conn = channel.getConnection().getTransportConnection();

      HornetQBuffer buffer = packet.encode(channel.getConnection());

      conn.write(buffer, false, false);
   }
View Full Code Here

                     Packet packet = new PacketImpl(PacketImpl.SESS_START);

                     packet.setChannelID(channel.getID());

                     Connection conn = channel.getConnection().getTransportConnection();

                     HornetQBuffer buffer = packet.encode(channel.getConnection());

                     conn.write(buffer, false, false);
                  }

                  resetCreditManager = true;
               }
View Full Code Here

   private void sendPacketWithoutLock(final Packet packet)
   {
      packet.setChannelID(channel.getID());

      Connection conn = channel.getConnection().getTransportConnection();

      HornetQBuffer buffer = packet.encode(channel.getConnection());

      conn.write(buffer, false, false);
   }
View Full Code Here

                                     new DummyConnectionLifeCycleListener(null),
                                     threadPool,
                                     threadPool,
                                     scheduledThreadPool);
      connector.start();
      Connection conn = connector.createConnection();
      connCreatedLatch.await(5, TimeUnit.SECONDS);
      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         conn.write(buff);
         HornetQBuffer buff2 = conn.createBuffer(8);
         buff2.writeInt(4);
         buff2.writeInt(i);
         acceptorListener.connection.write(buff2);
      }
      Assert.assertTrue(acceptorLatch.await(10, TimeUnit.SECONDS));
      Assert.assertTrue(connectorLatch.await(10, TimeUnit.SECONDS));
      conn.close();
      Assert.assertEquals(acceptorHandler.messagesReceieved, numPackets);
      Assert.assertEquals(connectorHandler.messagesReceieved, numPackets);
      int i = 0;
      for (Integer j : acceptorHandler.messages)
      {
View Full Code Here

                                     new DummyConnectionLifeCycleListener(null),
                                     threadPool,
                                     threadPool,
                                     scheduledThreadPool);
      connector.start();
      Connection conn = connector.createConnection();
      connCreatedLatch.await(5, TimeUnit.SECONDS);
      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         conn.write(buff);
      }
      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         acceptorListener.connection.write(buff);
      }
      Assert.assertTrue(acceptorLatch.await(10, TimeUnit.SECONDS));
      Assert.assertTrue(connectorLatch.await(10, TimeUnit.SECONDS));
      conn.close();
      Assert.assertEquals(acceptorHandler.messagesReceieved, numPackets);
      Assert.assertEquals(connectorHandler.messagesReceieved, numPackets);
      int i = 0;
      for (Integer j : acceptorHandler.messages)
      {
View Full Code Here

                                     new DummyConnectionLifeCycleListener(null),
                                     threadPool,
                                     threadPool,
                                     scheduledThreadPool);
      connector.start();
      Connection conn = connector.createConnection();
      connCreatedLatch.await(5, TimeUnit.SECONDS);
      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         acceptorListener.connection.write(buff);
      }

      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         conn.write(buff);
      }
      acceptorLatch.await(10, TimeUnit.SECONDS);
      connectorLatch.await(10, TimeUnit.SECONDS);
      conn.close();
      Assert.assertEquals(acceptorHandler.messagesReceieved, numPackets);
      Assert.assertEquals(connectorHandler.messagesReceieved, numPackets);
      int i = 0;
      for (Integer j : acceptorHandler.messages)
      {
View Full Code Here

                                     new DummyConnectionLifeCycleListener(null),
                                     threadPool,
                                     threadPool,
                                     scheduledThreadPool);
      connector.start();
      Connection conn = connector.createConnection();
      connCreatedLatch.await(5, TimeUnit.SECONDS);
      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         acceptorListener.connection.write(buff);
      }

      HornetQBuffer buff = conn.createBuffer(8);
      buff.writeInt(4);
      buff.writeInt(0);
      conn.write(buff);

      acceptorLatch.await(10, TimeUnit.SECONDS);
      connectorLatch.await(10, TimeUnit.SECONDS);
      conn.close();
      Assert.assertEquals(acceptorHandler.messagesReceieved, 1);
      Assert.assertEquals(connectorHandler.messagesReceieved, numPackets);
      int i = 0;
      for (Integer j : acceptorHandler.messages)
      {
View Full Code Here

                                     new DummyConnectionLifeCycleListener(null),
                                     threadPool,
                                     threadPool,
                                     scheduledThreadPool);
      connector.start();
      Connection conn = connector.createConnection();
      connCreatedLatch.await(5, TimeUnit.SECONDS);
      for (int i = 0; i < numPackets; i++)
      {
         HornetQBuffer buff = conn.createBuffer(8);
         buff.writeInt(4);
         buff.writeInt(i);
         acceptorListener.connection.write(buff);
      }

      acceptorLatch.await(10, TimeUnit.SECONDS);
      connectorLatch.await(10, TimeUnit.SECONDS);
      conn.close();
      Assert.assertEquals(acceptorHandler.messagesReceieved, 0);
      Assert.assertEquals(connectorHandler.messagesReceieved, numPackets);
      int i = 0;
      for (Integer j : acceptorHandler.messages)
      {
View Full Code Here

TOP

Related Classes of org.hornetq.spi.core.remoting.Connection

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.