Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 
 package org.jboss.remoting.transporter;
 
 
 import java.util.List;
 import java.util.Map;

The remoting server to expose the target POJO. This should be called on as a factory via static methods.

Author(s):
Tom Elrod
 
 public class TransporterServer
 {
    private Connector connector = null;

   
Creates a remoting server using the provided locator and subsytem and creating a TransporterHandler which takes the specified target object.

Parameters:
locator
target
subsystem
Throws:
java.lang.Exception
 
    public TransporterServer(InvokerLocator locatorObject targetString subsystemthrows Exception
    {
        = getConnector(locatornullnull);
       ServerInvocationHandler handler = new TransporterHandler(target);
       if (subsystem != null)
       {
          .addInvocationHandler(subsystem.toUpperCase(), handler);
       }
       else
       {
          addInterfaceSubsystems(handlertarget);
       }
    }

   
Creates a remoting server using the provided locator and subsytem and creating a TransporterHandler which takes the specified target object.

Parameters:
xmlConfig
target
subsystem
Throws:
java.lang.Exception
 
    public TransporterServer(Element xmlConfigObject targetString subsystemthrows Exception
    {
        = getConnector(nullnullxmlConfig);
       ServerInvocationHandler handler = new TransporterHandler(target);
       if (subsystem != null)
       {
          .addInvocationHandler(subsystem.toUpperCase(), handler);
       }
       else
       {
          addInterfaceSubsystems(handlertarget);
       }
    }

   
Creates a remoting server using the provided locator and subsytem and creating a TransporterHandler which takes the specified target object.

Parameters:
locator
target
subsystem
config - configuration data for Connector
Throws:
java.lang.Exception
   public TransporterServer(InvokerLocator locatorObject targetString subsystemMap configthrows Exception
   {
       = getConnector(locatorconfignull);
      ServerInvocationHandler handler = new TransporterHandler(target);
      if (subsystem != null)
      {
         .addInvocationHandler(subsystem.toUpperCase(), handler);
      }
      else
      {
         addInterfaceSubsystems(handlertarget);
      }
   }
   private void addInterfaceSubsystems(Connector connectorServerInvocationHandler handlerObject targetthrows Exception
   {
      Class targetClass = target.getClass();
      //first have to build list of interface names
      List interfaceNames = new ArrayList();
      populateInterfaceNames(interfaceNamestargetClass);
      for (int i = 0; i < interfaceNames.size(); i++)
      {
         String interfaceClassName = (StringinterfaceNames.get(i);
         connector.addInvocationHandler(interfaceClassName.toUpperCase(), handler);
      }
   }
   private void populateInterfaceNames(List interfaceNamesClass targetClass)
   {
      Class[] interfaces = targetClass.getInterfaces();
      if (interfaces != null)
      {
         for (int x = 0; x < interfaces.lengthx++)
         {
            interfaceNames.add(interfaces[x].getName());
            populateInterfaceNames(interfaceNamesinterfaces[x]);
         }
      }
   }

   
Returns the connector that this transporter server will use. Subclasses are free to override this method in order to create a more customized connector.

Parameters:
locator
config configuration data for connector
xmlConfig configuration data for connector (in xml form)
Returns:
the connector to be used by this transporter server
Throws:
java.lang.Exception
   protected Connector getConnector(InvokerLocator locatorMap configElement xmlConfig)
         throws Exception
   {
      Connector c = new Connector(locatorconfig);
      if (xmlConfig != null)
      {
         c.setConfiguration(xmlConfig);
      }
      c.create();
      return c;
   }

   
Adds a transporter handler to receive remote invocations on the target object passed.

Parameters:
target the target implementation to call on
proxyclassname the fully qualified classname of the interface that clients will use to call on
   public void addHandler(Object targetString proxyclassnamethrows Exception
   {
      if ( != null)
      {
         .addInvocationHandler(proxyclassnamenew TransporterHandler(target));
      }
      else
      {
         throw new Exception("Can not add handler to transporter server as has not be initialized yet.");
      }
   }

   
Starts the remoting server. This is called automatically upon any of the static createTransporterServer() methods.

   public void start() throws Exception
   {
      .start();
   }

   
Stops the remoting server. This must be called when no longer want to expose the target POJO for remote method calls.
   public void stop()
   {
      .stop();
   }

   
Creates a MBeanServer and MulticastDetector to start publishing detection messages so other detectors will be aware this server is available.

   private static void setupDetector() throws Exception
   {
      InternalTransporterServices services = InternalTransporterServices.getInstance();
      // if no one has setup our internal services yet, let's do it now
      if (!services.isSetup())
      {
         // we need an MBeanServer to store our network registry and multicast detector services
         MBeanServer server = MBeanServerFactory.createMBeanServer();
         // multicast detector will detect new network registries that come online
         MulticastDetector detector = new MulticastDetector();
         services.setup(serverdetectornullnullnulltruefalse);
         detector.start();
      }
      else if (services.getDetector() == null)
      {
         // the internal services singleton is already setup, make sure it has a detector because we need it
         MulticastDetector detector = new MulticastDetector();
         services.assignDetector(detectornulltrue);
         detector.start();
      }
      return;
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. This must be the fully qualified name of the interface for clients to use a the remote proxy to the target POJO. Otherwise, clustering will not work, as this is the value used to identifiy remote POJOs on the client side. If not clustered, this is not as critical, and simply use the fully qualified class name of the POJO if desired.
isClustered - true indicates that would like this server to be considered available for failover from clients calling on the same interface as exposed by the subsystem value. False will only allow those client that explicitly targeting this server to make calls on it.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(InvokerLocator locatorObject target,
                                                           String subsystemboolean isClusteredthrows Exception
   {
      return createTransporterServer(locatortargetsubsystemnullisClustered);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. This must be the fully qualified name of the interface for clients to use a the remote proxy to the target POJO. Otherwise, clustering will not work, as this is the value used to identifiy remote POJOs on the client side. If not clustered, this is not as critical, and simply use the fully qualified class name of the POJO if desired.
config - the configuration to be used in setting up the Connector.
isClustered - true indicates that would like this server to be considered available for failover from clients calling on the same interface as exposed by the subsystem value. False will only allow those client that explicitly targeting this server to make calls on it.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(InvokerLocator locatorObject target,
                                                           String subsystemMap configboolean isClusteredthrows Exception
   {
      if (isClustered && (InternalTransporterServices.getInstance().getDetector() == null))
      {
         setupDetector();
      }
      TransporterServer server = new TransporterServer(locatortargetsubsystemconfig);
      server.start();
      return server;
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locatorURI - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. This must be the fully qualified name of the interface for clients to use a the remote proxy to the target POJO. Otherwise, clustering will not work, as this is the value used to identifiy remote POJOs on the client side. If not clustered, this is not as critical, and simply use the fully qualified class name of the POJO if desired.
isClustered - true indicates that would like this server to be considered available for failover from clients calling on the same interface as exposed by the subsystem value. False will only allow those client that explicitly targeting this server to make calls on it.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(String locatorURIObject target,
                                                           String subsystemboolean isClusteredthrows Exception
   {
      return createTransporterServer(new InvokerLocator(locatorURI), targetsubsystemnullisClustered);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locatorURI - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. This must be the fully qualified name of the interface for clients to use a the remote proxy to the target POJO. Otherwise, clustering will not work, as this is the value used to identifiy remote POJOs on the client side. If not clustered, this is not as critical, and simply use the fully qualified class name of the POJO if desired.
config - the configuration data for the Connector.
isClustered - true indicates that would like this server to be considered available for failover from clients calling on the same interface as exposed by the subsystem value. False will only allow those client that explicitly targeting this server to make calls on it.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(String locatorURIObject target,
                                                           String subsystemMap configboolean isClusteredthrows Exception
   {
      return createTransporterServer(new InvokerLocator(locatorURI), targetsubsystemconfigisClustered);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object. Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
xmlconfig - specifies config for Connector
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. This must be the fully qualified name of the interface for clients to use a the remote proxy to the target POJO. Otherwise, clustering will not work, as this is the value used to identifiy remote POJOs on the client side. If not clustered, this is not as critical, and simply use the fully qualified class name of the POJO if desired.
isClustered - true indicates that would like this server to be considered available for failover from clients calling on the same interface as exposed by the subsystem value. False will only allow those client that explicitly targeting this server to make calls on it.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(Element xmlconfigObject target,
                                                           String subsystemboolean isClusteredthrows Exception
   {
      if (isClustered && (InternalTransporterServices.getInstance().getDetector() == null))
      {
         setupDetector();
      }
      TransporterServer server = new TransporterServer(xmlconfigtargetsubsystem);
      server.start();
      return server;
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. Can simply use the fully qualified class name of the POJO if desired.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(InvokerLocator locatorObject targetString subsystemthrows Exception
   {
      return createTransporterServer(locatortargetsubsystemfalse);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(InvokerLocator locatorObject targetthrows Exception
   {
      return createTransporterServer(locatortargetfalse);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
isClustered - indicates if want automatic failover on calls to remote servers.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(InvokerLocator locatorObject targetboolean isClusteredthrows Exception
   {
      if (isClustered && (InternalTransporterServices.getInstance().getDetector() == null))
      {
         setupDetector();
      }
      TransporterServer server = new TransporterServer(locatortargetnullnull);
      server.start();
      return server;
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(String locatorObject targetthrows Exception
   {
      return createTransporterServer(new InvokerLocator(locator), targetfalse);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locator - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
isClustered - indicates if want automatic failover on calls to remote servers.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(String locatorObject targetboolean isClusteredthrows Exception
   {
      return createTransporterServer(new InvokerLocator(locator), targetisClustered);
   }

   
Creates a remoting server based on given locator. Will convert any remote invocation requests into method calls on the given target object.Note: the TransporterServer instance returned will be a live (started) instance. Once the TransporterServer has been returned, it will have already been started automatically, so is a live server ready to receive requests.

Parameters:
locatorURI - specifies what transport, host and port binding, etc. to use by the remoting server.
target - the target POJO to receive the method call upon getting remote invocation requests.
subsystem - the name under which to register the handler within the remoting server. Can simply use the fully qualified class name of the POJO if desired.
Returns:
TransporterServer. Note, it will already be started upon return.
Throws:
java.lang.Exception
   public static TransporterServer createTransporterServer(String locatorURIObject targetString subsystemthrows Exception
   {
      return createTransporterServer(new InvokerLocator(locatorURI), targetsubsystemfalse);
   }
New to GrepCode? Check out our FAQ X