Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * 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,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 1999-2001 by HP Bluestone Software, Inc. All rights Reserved.
  *
  * HP Arjuna Labs,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id: TransactionStatusManager.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.arjuna.recovery ;
 
 

Author(s):
Dave Elsworthy (david_elsworthy@hp.com)
Version:
$Id: TransactionStatusManager.java 2342 2006-03-30 13:06:17Z $
Since:
HPTS 3.0.
 
 
 {
    public TransactionStatusManager()
    {
       startnull, -1 ) ;
    }
 
    public TransactionStatusManagerint port )
    {
       startnullport ) ;
    }
 
    public TransactionStatusManagerString serviceName )
    {
       startserviceNamenull, -1 ) ;
    }
 
    public TransactionStatusManagerString serviceNameint port  )
    {
       startserviceNamenullport ) ;
    }

   
The work item to be executed. this must be private as it should only be called once. otherwise we leak listener threads
 
    private void addServiceService serviceServerSocket serverSocket )
    {
       try
       {
           = new ListenerserverSocketservice );
          .setDaemon(true);
 
 							  Integer.toString(serverSocket.getLocalPort()));
 
          .start() ;
       }
       catch ( IOException ex ) {
       }
    }
 
    /*
     * Removes the TransactionStatusManager from the object store
    * and closes down the listener thread.
    * this will never work as a finalizer because the listener thread is always running and keeping this
    * instance from being garbage collected. we need a proper shutdonw method which closes the
    * listener socket causing the thread to shut down
    *
   // TODO consider adding a shutdown operation (signature change)
   public void finalize()
   {
       if ( ! _finalizeCalled )
       {
	  _finalizeCalled = true ;
	   _listener.stopListener() ;
	   TransactionStatusManagerItem.removeThis( Utility.getProcessUid() ) ;
      }
   }
    */

   
Create service and Transaction status manager item.
   private void startString serviceNameString hostint port )
   {
       try
       {
           Service service = ClassloadingUtility.loadAndInstantiateClass(Service.classserviceName,  null);
           if(service == null) {
               ..warn_recovery_TransactionStatusManager_4(serviceName);
               return;
           }
           ServerSocket socketServer = getTsmServerSocket(hostport);
           addServiceservicesocketServer ) ;
           TransactionStatusManagerItem.createAndSave(socketServer.getInetAddress().getHostAddress(), socketServer.getLocalPort() ) ;
                   socketServer.getInetAddress().getHostAddress(), serviceName);
       }
       catch ( IOException ex ) {
       }
   }
    public void shutdown()
    {
        if ( != null) {
            .stopListener() ;
            TransactionStatusManagerItem.removeThis( Utility.getProcessUid() ) ;
             = null;
        }
    }
    
Lookup the listener port for the transaction manager

Parameters:
defValue the value to use if no valid port number can be found
Returns:
the listener port
    private int getListenerPort(Integer defValue)
    {
        // has the port already been bound
        if ( > 0)
            return ;
        return recoveryPropertyManager.getRecoveryEnvironmentBean().getTransactionStatusManagerPort();
    }
    private String getListenerHostName()
    {
        return recoveryPropertyManager.getRecoveryEnvironmentBean().getTransactionStatusManagerAddress();
    }

    
Create a new listener socket. If the input paramters are invalid use the config properties to choose the desired address and port to bind the listener to. A port value of -1 is considered invalid.

Parameters:
hostNameOverride override the config property for the hostname
portOverride override the config property for the port
Returns:
a socket bound to the appropriate host and port
Throws:
java.io.IOException if the host name is unknown
    private ServerSocket getTsmServerSocket (String hostNameOverrideint portOverridethrows IOException
    {
        if ( != null)
        {
            // the socket has already been created
            return ;
        }
        if ( == -1)
        {
            // a previous attempt to create the socket failed
        }
        try
        {
            String host = hostNameOverride == null ? getListenerHostName() : hostNameOverride;
            InetAddress bindAddress = Utility.hostNameToInetAddress(host);
             = portOverride == -1 ? getListenerPort(null) : portOverride;
             = new ServerSocket(.bindAddress);
             = .getLocalPort();
        }
        catch (UnknownHostException ex)
        {
             = -1;
            throw ex;
        }
        return ;
    }

    
Listener thread.
    private Listener _listener ;

    
Default service run on listener thread.
    private static final String _defaultTsmService = "com.arjuna.ats.arjuna.recovery.ActionStatusService" ;

    
Flag used to ensure finalize gets called just once.
    private boolean _finalizeCalled = false ;

    
The listener socket
    private ServerSocket _socket;

    
Bound port for listener socket A value of -1 means that the attempt to create the socket failed
    private int _port = 0;

    
Default bind port is any port
    private int DEFAULT_TMS_PORT = 0;
New to GrepCode? Check out our FAQ X