Package org.jgroups

Examples of org.jgroups.Channel


      {
         Collection channels = (Collection) verifiable;
         for (Iterator iter = channels.iterator(); iter.hasNext();)
         {
            FlushTestReceiver receiver = (FlushTestReceiver) iter.next();
            Channel ch = receiver.getChannel();
            assertEquals("Correct view",ch.getView().getMembers().size(),expectedViewSize);
            assertTrue("Channel open",ch.isOpen());
            assertTrue("Chnanel connected",ch.isConnected());      
            assertNotNull("Valid address ", ch.getLocalAddress());
            assertTrue("Address included in view ", ch.getView().getMembers().contains(ch.getLocalAddress()));
            assertNotNull("Valid cluster name ", ch.getClusterName());
         }
        
        
         //verify views for pair services created on top of different "real" channels
         if(expectedViewSize>1 && isMuxChannelUsed())
         {           
            for (Iterator iter = channels.iterator(); iter.hasNext();)
            {
               FlushTestReceiver receiver = (FlushTestReceiver) iter.next();
               MuxChannel ch = (MuxChannel)receiver.getChannel();
               int servicePairs = 1;
               for (Iterator it = channels.iterator(); it.hasNext();)
               {       
                  FlushTestReceiver receiver2 = (FlushTestReceiverit.next();
                  MuxChannel ch2 = (MuxChannel)receiver2.getChannel();
                  if(ch.getId().equals(ch2.getId()) && !ch.getLocalAddress().equals(ch2.getLocalAddress()))
                  {                    
                     assertEquals("Correct view for service pair",ch.getView(),ch2.getView());
                     assertTrue("Presence in view",ch.getView().getMembers().contains(ch.getLocalAddress()));
                     assertTrue("Presence in view",ch.getView().getMembers().contains(ch2.getLocalAddress()));
                     assertTrue("Presence in view",ch2.getView().getMembers().contains(ch2.getLocalAddress()));
                     assertTrue("Presence in view",ch2.getView().getMembers().contains(ch.getLocalAddress()));
                     servicePairs++;                   
                  }
               }
               assertEquals("Correct service count",expectedViewSize,servicePairs);                           
            }           
View Full Code Here


      }
   }

   public void testBasicStateSync() throws Exception {

      Channel channel = new JChannel(CHANNEL_PROPS);
      channel.setOpt(Channel.LOCAL, Boolean.FALSE);

      channel.connect(GROUP_NAME);

      Thread.sleep(1000);

      boolean join = false;
      join = channel.getState(null, 100000l);
      assertTrue(join);

      Object tmp;
      int cnt = -1;
      while (true) {
         try {
            tmp = channel.receive(0);
            if (tmp instanceof ExitEvent) {
               break;
            }
            if (tmp instanceof SetStateEvent) {
               cnt = ((Integer) Util.objectFromByteBuffer(((SetStateEvent) tmp).getArg())).intValue();
               System.err.println("--  SetStateEvent, cnt=" + cnt);
               continue;
            }
            if ( tmp instanceof Message ) {
               if (cnt != -1) {
                  int msg = ((Integer) ((Message) tmp).getObject()).intValue();
                  assertEquals(cnt, msg - 1);
                  break// done
               }
            }
         } catch (ChannelNotConnectedException not) {
            break;
         } catch (ChannelClosedException closed) {
            break;
         } catch (Exception e) {
            System.err.println(e);
         }
      }

      channel.close();
   }
View Full Code Here

      return values;
   }

   public static DISCARD getDiscardForCache(Cache<?, ?> c) throws Exception {
      JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractComponent(c, Transport.class);
      Channel ch = jgt.getChannel();
      ProtocolStack ps = ch.getProtocolStack();
      DISCARD discard = new DISCARD();
      ps.insertProtocol(discard, ProtocolStack.ABOVE, TP.class);
      return discard;
   }
View Full Code Here

    * @return a reference to the DELAY instance being used by the JGroups stack
    * @throws Exception
    */
   public static DELAY setDelayForCache(Cache<?, ?> cache, int in_delay_millis, int out_delay_millis) throws Exception {
      JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractComponent(cache, Transport.class);
      Channel ch = jgt.getChannel();
      ProtocolStack ps = ch.getProtocolStack();
      DELAY delay = new DELAY();
      delay.setInDelay(in_delay_millis);
      delay.setOutDelay(out_delay_millis);
      ps.insertProtocol(delay, ProtocolStack.ABOVE, TP.class);
      return delay;
View Full Code Here

   // ChannelSource -------------------------------------------------

   public Channel getChannel()
   {
      Channel result = null;
      if (cache != null)
      {
         result = cache.getConfiguration().getRuntimeConfig().getChannel();
      }
      return result;
View Full Code Here

    * @param members
    * @return
    */
   private List<Address> checkBuddyStatus(List<Address> members)
   {
      Channel ch = configuration.getRuntimeConfig().getChannel();
      View currentView = ch.getView();
      List<Address> deadBuddies = new LinkedList<Address>();
      for (Address a : members) if (!currentView.containsMember(a)) deadBuddies.add(a);
      return deadBuddies;
   }
View Full Code Here

      RuntimeConfig rtcfg = cfg.getRuntimeConfig();

      // Only inject if there isn't already a channel or factory
      if (rtcfg.getMuxChannelFactory() == null && rtcfg.getChannel() == null)
      {
         Channel ch;
         try
         {
            ch = multiplexerService.createMultiplexerChannel(cfg.getMultiplexerStack(), cfg.getClusterName());
         }
         catch (Exception e)
View Full Code Here

   }
  
   private void configureMuxUpHandlerChannel(Cache<?, ?> cache) throws Exception
   {
      RuntimeConfig rc = cache.getConfiguration().getRuntimeConfig();
      Channel channel = rc.getChannel();
     
         if (channel == null)     
         {
            // TODO we could deal with other JBC mechanisms of configuring Channels, but in
            // reality the AS use cases that want MuxUpHandler shouldn't configure their
            // JBC that way
            ChannelFactory cf = rc.getMuxChannelFactory();
            if (cf == null)
            {
               log.debug("Cache " + cache.getConfiguration().getClusterName() +
                     " does not have a ChannelFactory injected so MuxUpHandler cannot be integrated");
            }
            String stack = cache.getConfiguration().getMuxStackName();
            if (stack == null)
            {
               log.debug("Cache " + cache.getConfiguration().getClusterName() +
                     " does not have a MuxStackName configured so MuxUpHandler cannot be integrated");
            }
            if (cf != null && stack != null)
            {
               // This doesn't result in JMX reg of channel              
               //channel = cf.createChannel(stack);
               channel = cf.createMultiplexerChannel(stack, cache.getConfiguration().getClusterName());
               rc.setChannel(new MuxHandlerChannel((JChannel) channel));
            }
         }
         else if (channel.getUpHandler() == null)
         {
            // replace
            rc.setChannel(new MuxHandlerChannel((JChannel) channel));
         }
         // else the Channel was injected and already had a handler -- shouldn't happen
View Full Code Here

   /**
    * {@inheritDoc}
    */
   protected Channel createChannel() throws Exception
   {
      Channel channel = new JChannel(configurator);
      channel.setOpt(Channel.AUTO_RECONNECT, true);
      return channel;
   }
View Full Code Here

    * @param members
    * @return
    */
   private List<Address> checkBuddyStatus(List<Address> members)
   {
      Channel ch = configuration.getRuntimeConfig().getChannel();
      View currentView = ch.getView();
      List<Address> deadBuddies = new LinkedList<Address>();
      for (Address a : members) if (!currentView.containsMember(a)) deadBuddies.add(a);
      return deadBuddies;
   }
View Full Code Here

TOP

Related Classes of org.jgroups.Channel

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.