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

SocketClientInvoker uses Sockets to remotely connect to the a remote ServerInvoker, which must be a SocketServerInvoker.

Author(s):
Jeff Haynie
Tom Elrod
Version:
$Revision: 5730 $
 
 {
    private static final Logger log = Logger.getLogger(SocketClientInvoker.class);
    private static final boolean isTraceEnabled = .isTraceEnabled();
 
    public static final String SO_TIMEOUT_FLAG = "timeout";

   
Default value for socket timeout is 30 minutes.
 
    public static final int SO_TIMEOUT_DEFAULT = 1800000;
 
    protected int timeout = ;
 
    private Constructor clientSocketConstructor = null;

   
Set number of retries in getSocket method
 
    public SocketClientInvoker(InvokerLocator locator)
    {
       this(locatornull);
    }
 
    public SocketClientInvoker(InvokerLocator locatorMap configuration)
    {
       super(locatorconfiguration);
       configureParameters();
    }
 
    protected ServerAddress createServerAddress()
    {
    }
 
 
    protected void configureParameters()
    {
       super.configureParameters();
       
       // For JBREM-1188
        = ;
       
       Map params = ;
       if (params != null)
       {
          // look for socketTimeout param
          Object val = params.get();
          if (val != null)
          {
             try
             {
                 = Integer.valueOf((Stringval).intValue();;
                .debug(this + " setting timeout to " + );
            }
            catch (Exception e)
            {
               .warn(this + " could not convert " +  + " value of " +
                        val + " to a int value.");
            }
         }
      }
   }
   protected Object handleException(Exception exSocketWrapper socketWrapper)
         throws ClassNotFoundExceptionMarshalException
   {
      .error("Got marshalling exception, exiting"ex);
      if (ex instanceof ClassNotFoundException)
      {
         //TODO: -TME Add better exception handling for class not found exception
         .error("Error loading classes from remote call result."ex);
         throw (ClassNotFoundExceptionex;
      }
      else if (ex instanceof SocketTimeoutException)
      {
         throw new MarshalException("Socket timed out.  Waited " + socketWrapper.getTimeout() + " milliseconds for response while calling on " +
                                    getLocator(), ex);
      }
      else if (ex instanceof InterruptedException && isWrapInterruptedException())
      {
         .debug(thisex);
         throw new RuntimeException(ex);
      }
      
      throw new MarshalException("Failed to communicate.  Problem during marshalling/unmarshalling"ex);
   }

   
used for debugging (tracing) connections leaks
   protected SocketWrapper createClientSocket(Socket socketint timeoutMap metadatathrows Exception
   {
      if ( == null)
      {
         if( == null)
         {
             = ClassLoaderUtility.loadClass(getClass(), );
         }
         try
         {
             = .getConstructor(new Class[]{Socket.classMap.classInteger.class});
         }
         catch (NoSuchMethodException e)
         {
             = .getConstructor(new Class[]{Socket.class});
         }
      }
      SocketWrapper clientSocketWrapper = null;
      if (.getParameterTypes().length == 3)
      {
         clientSocketWrapper = (SocketWrapper.newInstance(new Object[]{socketmetadatanew Integer(timeout)});
      }
      else
      {
         clientSocketWrapper = (SocketWrapper.newInstance(new Object[]{socket});
         clientSocketWrapper.setTimeout(timeout);
      }
      return clientSocketWrapper;
   }
   protected Socket createSocket(String addressint portint timeoutthrows IOException
   {
      Socket s = null;
      SocketFactory socketFactory = getSocketFactory();
      if (socketFactory != null)
      {
         s = socketFactory.createSocket();
      }
      else
      {
          s = new Socket();
      }
      InetSocketAddress inetAddr = new InetSocketAddress(addressport);
      
      if (timeout < 0)
      {
         timeout = getTimeout();
         if (timeout < 0)
            timeout = 0;
      }
      
      s.connect(inetAddrtimeout);
      return s;
   }
   {
      SocketWrapper socketWrapper = null;
      while (.size() > 0)
      {
         socketWrapper = (SocketWrapper.removeFirst();
         try
         {
            if (socketWrapper != null)
            {
               if (socketWrapper instanceof OpenConnectionChecker)
               {
                  ((OpenConnectionCheckersocketWrapper).checkOpenConnection();
               }
               if ()
               {
                  socketWrapper.checkConnection();
                  return socketWrapper;
               }
               else
               {
                  if (socketWrapper.getSocket().isConnected())
                  {
                     return socketWrapper;
                  }
                  else
                  {
                     try
                     {
                        socketWrapper.close();
                     }
                     catch (IOException e)
                     {
                     }
                     return null;
                  }
               }
            }
         }
         catch (Exception ex)
         {
            if ()
            {
               .trace("Couldn't reuse connection from pool");
            }
            try
            {
               socketWrapper.close();
            }
            catch (Exception ignored)
            {
            }
         }
      }
      return null;
   }


   
Getter for property timeout

Returns:
Value of property timeout
   public int getTimeout()
   {
      return ;
   }
   public String toString()
   {
      return "SocketClientInvoker[" + Integer.toHexString(System.identityHashCode(this)) + ", " +
         .getProtocol() + "://" + .getHost() + ":" + .getPort() + "]";
   }
New to GrepCode? Check out our FAQ X