Class TP

Direct Known Subclasses:
BasicTCP, LOOPBACK, SHARED_LOOPBACK, TUNNEL, UDP

public abstract class TP extends Protocol
Generic transport - specific implementations should extend this abstract class. Features which are provided to the subclasses include
  • version checking
  • marshalling and unmarshalling
  • message bundling (handling single messages, and message lists)
  • incoming packet handler
  • loopback
A subclass has to override The create() or start() method has to create a local address.invalid input: '<'br The receive(Address, Address, byte[], int, int) method must be called by subclasses when a unicast or multicast message has been received.
Version:
$Id: TP.java,v 1.160.2.38 2008/12/12 08:09:27 belaban Exp $
Author:
Bela Ban
  • Field Details

    • local_addr

      protected Address local_addr
      The address (host and port) of this member
    • channel_name

      protected String channel_name
      The name of the group to which this member is connected
    • bind_addr

      protected InetAddress bind_addr
      The interface (NIC) which should be used by this transport
    • members

      protected final HashSet<Address> members
      The members of this group (updated when a member joins or leaves)
    • view

      protected View view
    • discard_incompatible_packets

      protected boolean discard_incompatible_packets
      Discard packets with a different version. Usually minor version differences are okay. Setting this property to true means that we expect the exact same version on all incoming packets
    • thread_naming_pattern

      protected String thread_naming_pattern
      Names the current thread. Valid values are "pcl": p: include the previous (original) name, e.g. "Incoming thread-1", "UDP ucast receiver" c: include the cluster name, e.g. "MyCluster" l: include the local address of the current member, e.g. "192.168.5.1:5678"
    • timer

      protected TimeScheduler timer
      ================================== Timer thread pool =================================
    • timer_thread_factory

      protected ThreadFactory timer_thread_factory
    • global_thread_factory

      protected ThreadFactory global_thread_factory
      Used by all threads created by JGroups outside of the thread pools
    • pm

      protected PortsManager pm
    • persistent_ports_file

      protected String persistent_ports_file
    • pm_expiry_time

      protected long pm_expiry_time
    • persistent_ports

      protected boolean persistent_ports
  • Constructor Details

    • TP

      protected TP()
      Creates the TP protocol, and initializes the state variables, does however not start any sockets or threads.
  • Method Details

    • getThreadNamingPattern

      public String getThreadNamingPattern()
    • getOOBThreadPool

      public Executor getOOBThreadPool()
    • setOOBThreadPool

      public void setOOBThreadPool(Executor oob_thread_pool)
    • getOOBThreadPoolThreadFactory

      public ThreadFactory getOOBThreadPoolThreadFactory()
    • setOOBThreadPoolThreadFactory

      public void setOOBThreadPoolThreadFactory(ThreadFactory factory)
    • getDefaultThreadPool

      public Executor getDefaultThreadPool()
    • setDefaultThreadPool

      public void setDefaultThreadPool(Executor thread_pool)
    • getDefaultThreadPoolThreadFactory

      public ThreadFactory getDefaultThreadPoolThreadFactory()
    • setDefaultThreadPoolThreadFactory

      public void setDefaultThreadPoolThreadFactory(ThreadFactory factory)
    • getTimerThreadFactory

      public ThreadFactory getTimerThreadFactory()
    • setTimerThreadFactory

      public void setTimerThreadFactory(ThreadFactory factory)
    • getTimer

      public TimeScheduler getTimer()
    • getThreadFactory

      public ThreadFactory getThreadFactory()
      Description copied from class: Protocol
      Supposed to be overwritten by subclasses. Usually the transport returns a valid non-null thread factory, but thread factories can also be created by individual protocols
      Overrides:
      getThreadFactory in class Protocol
      Returns:
    • setThreadFactory

      public void setThreadFactory(ThreadFactory factory)
    • toString

      public String toString()
      debug only
      Overrides:
      toString in class Object
    • resetStats

      public void resetStats()
      Overrides:
      resetStats in class Protocol
    • registerProbeHandler

      public void registerProbeHandler(TP.ProbeHandler handler)
    • unregisterProbeHandler

      public void unregisterProbeHandler(TP.ProbeHandler handler)
    • getNumMessagesSent

      public long getNumMessagesSent()
    • getNumMessagesReceived

      public long getNumMessagesReceived()
    • getNumBytesSent

      public long getNumBytesSent()
    • getNumBytesReceived

      public long getNumBytesReceived()
    • getBindAddress

      public String getBindAddress()
    • setBindAddress

      public void setBindAddress(String bind_addr) throws UnknownHostException
      Throws:
      UnknownHostException
    • getBindPort

      public int getBindPort()
    • setBindPort

      public void setBindPort(int port)
    • getBindToAllInterfaces

      public boolean getBindToAllInterfaces()
      Deprecated.
    • setBindToAllInterfaces

      public void setBindToAllInterfaces(boolean flag)
    • isReceiveOnAllInterfaces

      public boolean isReceiveOnAllInterfaces()
    • getReceiveInterfaces

      public List getReceiveInterfaces()
    • isSendOnAllInterfaces

      public boolean isSendOnAllInterfaces()
    • getSendInterfaces

      public List getSendInterfaces()
    • isDiscardIncompatiblePackets

      public boolean isDiscardIncompatiblePackets()
    • setDiscardIncompatiblePackets

      public void setDiscardIncompatiblePackets(boolean flag)
    • isEnableBundling

      public boolean isEnableBundling()
    • setEnableBundling

      public void setEnableBundling(boolean flag)
    • isEnable_unicast_bundling

      public boolean isEnable_unicast_bundling()
    • setEnable_unicast_bundling

      public void setEnable_unicast_bundling(boolean enable_unicast_bundling)
    • getMaxBundleSize

      public int getMaxBundleSize()
    • setMaxBundleSize

      public void setMaxBundleSize(int size)
    • getMaxBundleTimeout

      public long getMaxBundleTimeout()
    • setMaxBundleTimeout

      public void setMaxBundleTimeout(long timeout)
    • getLocalAddress

      public Address getLocalAddress()
    • getChannelName

      public String getChannelName()
    • isLoopback

      public boolean isLoopback()
    • setLoopback

      public void setLoopback(boolean b)
    • isUseIncomingPacketHandler

      public boolean isUseIncomingPacketHandler()
    • isDefaulThreadPoolEnabled

      public boolean isDefaulThreadPoolEnabled()
    • isOOBThreadPoolEnabled

      public boolean isOOBThreadPoolEnabled()
    • getUpProtocols

      public ConcurrentMap<String,Protocol> getUpProtocols()
    • getOOBMinPoolSize

      public int getOOBMinPoolSize()
    • setOOBMinPoolSize

      public void setOOBMinPoolSize(int size)
    • getOOBMaxPoolSize

      public int getOOBMaxPoolSize()
    • setOOBMaxPoolSize

      public void setOOBMaxPoolSize(int size)
    • getOOBPoolSize

      public int getOOBPoolSize()
    • getOOBKeepAliveTime

      public long getOOBKeepAliveTime()
    • setOOBKeepAliveTime

      public void setOOBKeepAliveTime(long time)
    • getOOBMessages

      public long getOOBMessages()
    • getOOBQueueSize

      public int getOOBQueueSize()
    • getOOBMaxQueueSize

      public int getOOBMaxQueueSize()
    • getIncomingMinPoolSize

      public int getIncomingMinPoolSize()
    • setIncomingMinPoolSize

      public void setIncomingMinPoolSize(int size)
    • getIncomingMaxPoolSize

      public int getIncomingMaxPoolSize()
    • setIncomingMaxPoolSize

      public void setIncomingMaxPoolSize(int size)
    • getIncomingPoolSize

      public int getIncomingPoolSize()
    • getIncomingKeepAliveTime

      public long getIncomingKeepAliveTime()
    • setIncomingKeepAliveTime

      public void setIncomingKeepAliveTime(long time)
    • getIncomingMessages

      public long getIncomingMessages()
    • getIncomingQueueSize

      public int getIncomingQueueSize()
    • getIncomingMaxQueueSize

      public int getIncomingMaxQueueSize()
    • dumpStats

      public Map<String,Object> dumpStats()
      Overrides:
      dumpStats in class Protocol
    • sendToAllMembers

      public abstract void sendToAllMembers(byte[] data, int offset, int length) throws Exception
      Send to all members in the group. UDP would use an IP multicast message, whereas TCP would send N messages, one for each member
      Parameters:
      data - The data to be sent. This is not a copy, so don't modify it
      offset -
      length -
      Throws:
      Exception
    • sendToSingleMember

      public abstract void sendToSingleMember(Address dest, byte[] data, int offset, int length) throws Exception
      Send to all members in the group. UDP would use an IP multicast message, whereas TCP would send N messages, one for each member
      Parameters:
      dest - Must be a non-null unicast address
      data - The data to be sent. This is not a copy, so don't modify it
      offset -
      length -
      Throws:
      Exception
    • getInfo

      public abstract String getInfo()
    • postUnmarshalling

      public abstract void postUnmarshalling(Message msg, Address dest, Address src, boolean multicast)
    • postUnmarshallingList

      public abstract void postUnmarshallingList(Message msg, Address dest, boolean multicast)
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
      Overrides:
      init in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
    • destroy

      public void destroy()
      Description copied from class: Protocol
      This method is called on a Channel.close(). Does some cleanup; after the call the VM will terminate
      Overrides:
      destroy in class Protocol
    • start

      public void start() throws Exception
      Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
      Overrides:
      start in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so Channel.connect(String) will throw an exception
    • stop

      public void stop()
      Description copied from class: Protocol
      This method is called on a Channel.disconnect(). Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
      Overrides:
      stop in class Protocol
    • handleConnect

      protected void handleConnect() throws Exception
      Throws:
      Exception
    • handleDisconnect

      protected void handleDisconnect()
    • getSingletonName

      public String getSingletonName()
    • setProperties

      public boolean setProperties(Properties props)
      Setup the Protocol instance according to the configuration string
      Overrides:
      setProperties in class Protocol
      Returns:
      true if no other properties are left. false if the properties still have data in them, ie , properties are left over and not handled by the protocol stack
    • up

      public Object up(Event evt)
      handle the UP event.
      Overrides:
      up in class Protocol
      Parameters:
      evt - - the event being send from the stack
    • down

      public Object down(Event evt)
      Caller by the layer above this layer. Usually we just put this Message into the send queue and let one or more worker threads handle it. A worker thread then removes the Message from the send queue, performs a conversion and adds the modified Message to the send queue of the layer below it, by calling down()).
      Overrides:
      down in class Protocol
    • receive

      protected final void receive(Address dest, Address sender, byte[] data, int offset, int length)
      Subclasses must call this method when a unicast or multicast message has been received. Declared final so subclasses cannot override this method.
      Parameters:
      dest -
      sender -
      data -
      offset -
      length -
    • handleDownEvent

      protected Object handleDownEvent(Event evt)
    • setThreadNames

      protected void setThreadNames()
    • unsetThreadNames

      protected void unsetThreadNames()
    • handleConfigEvent

      protected void handleConfigEvent(Map<String,Object> map)
    • createThreadPool

      protected static ExecutorService createThreadPool(int min_threads, int max_threads, long keep_alive_time, String rejection_policy, BlockingQueue<Runnable> queue, ThreadFactory factory)
    • passToAllUpProtocols

      protected void passToAllUpProtocols(Event evt)
    • sendUpLocalAddressEvent

      public void sendUpLocalAddressEvent()