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.transport.local;
 
 import  org.jboss.logging.Logger;
 
 import java.util.Map;

LocalClientInvoker does not use any transport protocol for invoking the ServerInvoker, instead will make call directly on it locally. This increases performance since no serialization required as well as needed for push callbacks where InvokerCallbackHandler is in same JVM as the callback server.

Author(s):
Tom Elrod
Version:
$Revision: 3956 $
 
 public class LocalClientInvoker extends AbstractInvoker implements BidirectionalClientInvoker
 {
    private static final Logger log = Logger.getLogger(LocalClientInvoker.class);
 
    private ServerInvoker serverInvoker;
    private boolean isConnected = false;
    private boolean byValue = false;
 
    public LocalClientInvoker(InvokerLocator locator)
    {
       super(locator);
    }
 
    public LocalClientInvoker(InvokerLocator locatorMap configuration)
    {
       super(locatorconfiguration);
    }
 
    public LocalClientInvoker(InvokerLocator locatorMap configurationboolean byValue)
    {
       super(locatorconfiguration);
       this. = byValue;
    }

   
transport a request against a remote ServerInvoker

Parameters:
invocation
Returns:
Throws:
Throwable
 
    public Object invoke(InvocationRequest invocationthrows Throwable
    {
       if(.isTraceEnabled())
       {
          .trace("Using local client invoker for invocation.");
       }
 
       InvocationRequest localInvocation = invocation;
 
       if()
       {
          localInvocation = marshallInvocation(localInvocation);
       }
      Object ret = null;
      if( != null)
      {
         try
         {
            ret = .invoke(localInvocation);
         }
         catch (ServerInvoker.InvalidStateException invalidStateEx)
         {
            if(.isTraceEnabled())
            {
               .trace("Error calling on " +  + " because is in invalid state.  Will retry with new server invoker.");
            }
            ServerInvoker newServerInvoker = null;
            // try to get new server invoker if one exists
            ServerInvoker[] invokers = InvokerRegistry.getServerInvokers();
            if(invokers != null)
            {
               for(int x = 0; x < invokers.lengthx++)
               {
                  ServerInvoker svrinvoker = invokers[x];
                  InvokerLocator svrlocator = svrinvoker.getLocator();
                  if(getLocator().equals(svrlocator))
                  {
                     newServerInvoker = svrinvoker;
                     break;
                  }
               }
            }
            // if new server invoker found, try invocation call again
            if(newServerInvoker != null)
            {
                = newServerInvoker;
               ret = .invoke(localInvocation);
            }
            else
            {
               throw invalidStateEx;
            }
         }
      }
      else
      {
         throw new ConnectionFailedException("Error invoking on server because " +
                                             "no local server to call upon.");
      }
      return ret;
   }
   {
      final Object param = localInvocation.getParameter();
      Object newParam = null;
      String serializationType = getSerializationType();
      final SerializationManager manager = SerializationStreamFactory.getManagerInstance(serializationType);
      if (serializationType.indexOf("jboss") < 0 || SecurityUtility.skipAccessControl())
      {
         newParam = manager.createMarshalledValueForClone(param).get();
      }
      else
      {
         try
         {
            newParam = AccessController.doPrivilegednew PrivilegedExceptionAction()
            {
               public Object run() throws Exception
               {
                  return manager.createMarshalledValueForClone(param).get();
               }
            });
         }
         catch (PrivilegedActionException e)
         {
            throw (IOExceptione.getCause();
         }
      }
      
      localInvocation.setParameter(newParam);
      return localInvocation;
   }

   
subclasses must provide this method to return true if their remote connection is connected and false if disconnected. in some transports, such as SOAP, this method may always return true, since the remote connectivity is done on demand and not kept persistent like other transports (such as socket-based transport).

Returns:
boolean true if connected, false if not
   public boolean isConnected()
   {
      return ;
   }

   
connect to the remote invoker

Throws:
ConnectionFailedException
   public void connect() throws ConnectionFailedException
   {
       = true;
   }

   
disconnect from the remote invoker. Once disconnect called will not be able to re-connect by calling connect since will loose reference to server invoker.
   public void disconnect()
   {
       = false;
   }
   public void setMarshaller(Marshaller marshaller)
   {
      // No op since is local, do not need marshaller
   }
   public Marshaller getMarshaller()
   {
      return null;
   }
   public void setUnMarshaller(UnMarshaller unmarshaller)
   {
      // No op since is local, do not need unmarshaller
   }
   {
      return null;
   }
   public void establishLease(String sessionIDMap configurationlong leasePeriodthrows Throwable
   {
      // noop since is local
   }
   public void terminateLease(String sessionIdint disconnectTimeout)
   {
      // noop since is local
   }
   public long getLeasePeriod(String sessionID)
   {
      return -1; // no lease, since is local
   }

   
This will set the local reference to the server invoker. This is needed to so can make calls directly against server.

Parameters:
svrInvoker
   public void setServerInvoker(ServerInvoker svrInvoker)
   {
      this. = svrInvoker;
   }
   public InvokerLocator getCallbackLocator(Map metadata)
   {
      String transport = (Stringmetadata.get(.);
      String host = (Stringmetadata.get(.);
      String sPort = (Stringmetadata.get(.);
      int port = -1;
      if (sPort != null)
      {
         try
         {
            port = Integer.parseInt(sPort);
         }
         catch (NumberFormatException e)
         {
            throw new RuntimeException("Can not set internal callback server port as configuration value (" + sPort + " is not a number.");
         }
      }
      return new InvokerLocator(transporthostport"callback"metadata);
   }
New to GrepCode? Check out our FAQ X