com.apama.net.beans
Class AbstractGenericComponentManagementBean

java.lang.Object
  extended by com.apama.net.beans.AbstractGenericComponentManagementBean
All Implemented Interfaces:
BaseClientInterface, PingClientInterface, PingOperationsInterface
Direct Known Subclasses:
GenericComponentManagementBean

public abstract class AbstractGenericComponentManagementBean
extends java.lang.Object
implements PingClientInterface

AbstractGenericComponentManagementBean is a JavaBean that provides a base class upon which JavaBeans using the remote GenericComponentManagement can be built.

Note that changes to the value of the "host", or "port" properties will cause the bean to attempt to re-connect to a server running on a new host/port. This re-connection will happen immediately if the bean was connected at the time of the property change, but will happen later in a "lazy" fashion if there was no existing connection at the time of the property change.

This bean also maintains Boolean bound property called "beanConnected", the value of which is maintained internally. The value will be set to true following a successfull connection to an server, and to false at the time of disconnection. Once connected, a background thread will periodically "ping" the remote server. This background thread will also maintain the value of the "beanConnected" property each time it tests the connection.

Warning: The bound properties supported by this bean will notify all registered listeners from within a synchronized block. Listeners should NOT invoke methods that would cause indirect calls back to synchronized methods in this bean. For example calls to System.exit(int) would cause a deadlock situation when the shutdown handler thread attempted to call disconnect(). However, direct calls from the listener onto synchronized methods of the bean (re-entry) is permitted.


Field Summary
static int DEFAULT_PORT
          The default value for the port property.
 
Fields inherited from interface com.apama.net.beans.interfaces.BaseClientInterface
COPYRIGHT, DEFAULT_CONNECTION_POLLING_INTERVAL, DEFAULT_HOST, DEFAULT_PROCESS_NAME, PRODUCTNAME, PROPERTY_BEAN_CONNECTED, PROPERTY_CONNECTION_POLLING_INTERVAL, PROPERTY_HOST, PROPERTY_PORT, PROPERTY_PROCESS_NAME, PROPERTY_VERBOSE, VERSION
 
Constructor Summary
AbstractGenericComponentManagementBean()
          Default constructor - as required to be a bean.
AbstractGenericComponentManagementBean(java.lang.String socket_hostname, int socket_port, java.lang.String processName)
          Full argument constructor.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a property change listener.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Add a property change listener for a specific named property.
 void connectNow()
          Manually request that the bean connects to the remote server.
 void disconnect()
          Disconnect from a remote server.
 void dispose()
          Disconnects the client and also waits to ensure that all background threads and other resources associated with this object have been terminated or freed.
 boolean getBeanConnected()
          Get the beanConnected property value.
 int getConnectionPollingInterval()
          Get the polling interval (in milliseconds) for the internal connection test thread.
 java.lang.String getHost()
          Get the name of the host to be connected to.
 int getPort()
          Get the port number to be connected to.
 java.lang.String getProcessName()
          Get the processName in use
 boolean getVerbose()
          Getter for the verbose property.
 boolean isBeanConnected()
          Another name for the getBeanConnected() method.
 void pingServer()
          Manually test if the remote agent process is alive and responding to client requests.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a property change listener.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Remove a property change listener for a specific named property.
 void setConnectionPollingInterval(int milliseconds)
          Set the polling interval (in milliseconds) for the internal connection test thread.
 void setHost(java.lang.String newHostValue)
          Setter for the host property.
 void setPort(int newPortValue)
          Setter for the port property.
 void setProcessName(java.lang.String newProcessName)
          Setter for the process name property.
 void setVerbose(boolean newVerboseValue)
          Setter for the verbose property.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default value for the port property.

Constructor Detail

AbstractGenericComponentManagementBean

public AbstractGenericComponentManagementBean()
Default constructor - as required to be a bean. Initialises the bean with default values for the properties. This default constructor does not make a connection to a remote server.


AbstractGenericComponentManagementBean

public AbstractGenericComponentManagementBean(java.lang.String socket_hostname,
                                              int socket_port,
                                              java.lang.String processName)
                                       throws GenericComponentManagementException
Full argument constructor. Calls the default constructor, then connects to a remote server.

Parameters:
socket_hostname - Name of the host where the server is running.
socket_port - Port number on which the server is listening.
processName - the process name to use
Throws:
GenericComponentManagementException - Thrown if any exceptions occur in the Client SDK.
Method Detail

connectNow

public void connectNow()
                throws com.apama.util.CompoundException
Manually request that the bean connects to the remote server. Repeated calls are permitted, and attempting to connect a bean that is already connected is identical to calling pingServer() from the PingOperationsInterface.

Specified by:
connectNow in interface BaseClientInterface
Throws:
com.apama.util.CompoundException - Thrown if any exceptions occur in the Client SDK.

dispose

public void dispose()
Description copied from interface: BaseClientInterface
Disconnects the client and also waits to ensure that all background threads and other resources associated with this object have been terminated or freed. This method should always be called before quitting the program. Never call this method while the target object is locked, or from a thread that is receiving events or handling a property change notification event from the target object.

Specified by:
dispose in interface BaseClientInterface

disconnect

public void disconnect()
                throws GenericComponentManagementException
Disconnect from a remote server. Removes the reference to the GenericComponentManagement object, and unhooks the ShutdownHook.

The beanConnected property is set to false, and the connection polling thread is terminated.

It is intended that subclasses that override this method call super.disconnect() as the last statement after finishing their local disconnect funtionality. Note however that it is _not_ necessary for all subclasses to override this method.

Specified by:
disconnect in interface BaseClientInterface
Throws:
GenericComponentManagementException - This implementation will never throw an exception, but subclasses will probably need to do so.

pingServer

public void pingServer()
                throws com.apama.util.CompoundException
Manually test if the remote agent process is alive and responding to client requests. This method makes a no-arg, void return, method call on the client interface of the agent. If a connection is not yet established, this method will request a connection. In the event that a connection cannot be established, or an error during the ping, a GenericComponentManagementException will be raised.

Specified by:
pingServer in interface PingOperationsInterface
Throws:
com.apama.util.CompoundException - when the ping fails.

getHost

public java.lang.String getHost()
Get the name of the host to be connected to. This is the name of the host on which the server is running.

Specified by:
getHost in interface BaseClientInterface
Returns:
Name of the host where the server to be monitored is running.

setHost

public void setHost(java.lang.String newHostValue)
             throws GenericComponentManagementException
Setter for the host property. This is the name of the host on which the server is running. Changing this property will cause any existing connection to be lost. If there was an existing connection, then a new connection will be created.

Specified by:
setHost in interface BaseClientInterface
Parameters:
newHostValue - The new value for the Host property.
Throws:
GenericComponentManagementException - Thrown if any exceptions occur in the Client SDK.

getPort

public int getPort()
Get the port number to be connected to. This is the port number on which the server is listening.

Specified by:
getPort in interface BaseClientInterface
Returns:
Port number on which the server is listening.

setPort

public void setPort(int newPortValue)
             throws GenericComponentManagementException
Setter for the port property. This is the port number on which the sentinel agent to be monitored is listening. Changing this property will cause any existing connection to be lost. If there was an existing connection, then a new connection will be created.

Specified by:
setPort in interface BaseClientInterface
Parameters:
newPortValue - The new value for the Port property.
Throws:
GenericComponentManagementException - Thrown if any exceptions occur in the Client SDK.

getProcessName

public java.lang.String getProcessName()
Get the processName in use

Specified by:
getProcessName in interface BaseClientInterface
Returns:
Process Name in use

setProcessName

public void setProcessName(java.lang.String newProcessName)
                    throws GenericComponentManagementException
Setter for the process name property. This is the process name to use. Changing this property will cause any existing connection to be lost. If there was an existing connection, then a new connection will be created.

Specified by:
setProcessName in interface BaseClientInterface
Parameters:
newProcessName - The new value for the process name property.
Throws:
GenericComponentManagementException - Thrown if any exceptions occur in the Client SDK.

isBeanConnected

public boolean isBeanConnected()
Another name for the getBeanConnected() method.

Specified by:
isBeanConnected in interface BaseClientInterface
Returns:
true if the bean has a connection to a server, false if not.

getBeanConnected

public boolean getBeanConnected()
Get the beanConnected property value. This is the status of the bean - connected, or not connected. It indicates if the AbstractGenericComponentManagementBean has a valid instance of the GenericComponentManagement interface.

Specified by:
getBeanConnected in interface BaseClientInterface
Returns:
true if the bean has a connection to a server, false if not.

getConnectionPollingInterval

public int getConnectionPollingInterval()
Get the polling interval (in milliseconds) for the internal connection test thread.

Specified by:
getConnectionPollingInterval in interface BaseClientInterface
Returns:
the current interval in milliseconds

setConnectionPollingInterval

public void setConnectionPollingInterval(int milliseconds)
Set the polling interval (in milliseconds) for the internal connection test thread. If the parameter is negative, then the default value will be used instead.

Specified by:
setConnectionPollingInterval in interface BaseClientInterface
Parameters:
milliseconds - the current interval in milliseconds

getVerbose

public boolean getVerbose()
Getter for the verbose property. When verbose is set to true, some methods (in subclasses) will print progress messages on stdout.

Returns:
Current value of the verbose property.

setVerbose

public void setVerbose(boolean newVerboseValue)
Setter for the verbose property. When verbose is set to true, some methods (in subclasses) will print progress messages on stdout.

Parameters:
newVerboseValue - Set to true for more verbose status output.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener.

Specified by:
removePropertyChangeListener in interface BaseClientInterface
Parameters:
listener - the listener to be removed.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener. Use this method to be informed whenever the a property value is changed.

Specified by:
addPropertyChangeListener in interface BaseClientInterface
Parameters:
listener - the listener to be added.

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Remove a property change listener for a specific named property.

Specified by:
removePropertyChangeListener in interface BaseClientInterface
Parameters:
propertyName - the name of the property that was listened on.
listener - the listener to be removed.

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Add a property change listener for a specific named property.

Specified by:
addPropertyChangeListener in interface BaseClientInterface
Parameters:
propertyName - the name of the property to listen on.
listener - the listener to be added.


Submit a bug or feature
Copyright (c) 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors. Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG