Class PingBean
- java.lang.Object
-
- com.apama.net.beans.PingBean
-
- All Implemented Interfaces:
BaseClientInterface,PingClientInterface,PingOperationsInterface,java.lang.AutoCloseable
public class PingBean extends java.lang.Object implements PingClientInterface, java.lang.AutoCloseable
PingBean is a JavaBean that provides a mechanism for pinging any Apama TCP server that offers the Pingable interface (that should be all of them).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 successful connection to a 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
-
Fields inherited from interface com.apama.net.beans.interfaces.BaseClientInterface
COPYRIGHT, DEFAULT_CONNECTION_POLLING_INTERVAL, DEFAULT_HOST, DEFAULT_PORT, DEFAULT_PROCESS_NAME, PRODUCTNAME, PROPERTY_BEAN_CONNECTED, PROPERTY_CONNECTION_POLLING_INTERVAL, PROPERTY_HOST, PROPERTY_PORT, PROPERTY_PROCESS_NAME, PROPERTY_VERBOSE, VERSION
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add a property change listener.voidaddPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)Add a property change listener for a specific named property.voidclose()Disconnects the client and also waits to ensure that all background threads and other resources associated with this object have been terminated or freed.voidconnectNow()Manually request that the bean connects to the remote server.voiddisconnect()Disconnect from an server.voiddispose()Deprecated.booleangetBeanConnected()Get the beanConnected property value.intgetConnectionPollingInterval()Get the polling interval (in milliseconds) for the internal connection test thread.java.lang.StringgetHost()Get the name of the host to be connected to.intgetPort()Get the port number to be connected to.java.lang.StringgetProcessName()Get the process Name in use This is the process name in use for this beanbooleanisBeanConnected()Another name for the getBeanConnected() method.booleanisPolling()Determine if the connection is being tested in a background thread.voidpingServer()Manually test if the remote server process is alive and responding to client requests.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Remove a property change listener.voidremovePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)Remove a property change listener for a specific named property.voidsetConnectionPollingInterval(int milliseconds)Set the polling interval (in milliseconds) for the internal connection test thread.voidsetHost(java.lang.String newHostValue)Setter for the host property.voidsetPort(int newPortValue)Setter for the port property.voidsetProcessName(java.lang.String newProcessName)Setter for the process Name This is the process name property to use Changing this property will cause any existing connection to be lost.
-
-
-
Constructor Detail
-
PingBean
public PingBean()
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.
-
PingBean
public PingBean(java.lang.String socket_hostname, int socket_port, java.lang.String processName) throws com.apama.util.CompoundExceptionFull argument constructor. Calls the default constructor, then connects to a remote server.- Parameters:
socket_hostname- Name of the host where the remote server is running.socket_port- Port number on which the remote server is listening.- Throws:
com.apama.util.CompoundException- Thrown if any exceptions occur in the Client SDK.
-
-
Method Detail
-
connectNow
public void connectNow() throws com.apama.util.CompoundExceptionManually 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 callingpingServer()from the PingOperationsInterface.- Specified by:
connectNowin interfaceBaseClientInterface- Throws:
com.apama.util.CompoundException- Thrown if any exceptions occur in the Client SDK.
-
disconnect
public void disconnect() throws com.apama.util.CompoundExceptionDisconnect from an server. Removes the reference to the PingableClient object.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 functionality. Note however that it is _not_ necessary for all subclasses to override this method.
- Specified by:
disconnectin interfaceBaseClientInterface- Throws:
com.apama.util.CompoundException- This implementation will never throw an exception, but subclasses will probably need to do so.
-
close
public void close()
Description copied from interface:BaseClientInterfaceDisconnects 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.This method is invoked automatically on objects managed by the try-with-resources statement.
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceBaseClientInterface- See Also:
AutoCloseable.close()
-
dispose
@Deprecated public void dispose()
Deprecated.Description copied from interface:BaseClientInterfaceDisconnects 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:
disposein interfaceBaseClientInterface
-
pingServer
public void pingServer() throws com.apama.util.CompoundExceptionManually test if the remote server process is alive and responding to client requests. This method makes a no-arg, void return, method call on the client interface of the server. 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, an CompoundException will be raised.- Specified by:
pingServerin interfacePingOperationsInterface- 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 remote server to be monitored is running.- Specified by:
getHostin interfaceBaseClientInterface- Returns:
- Name of the host where the remote server to be monitored is running.
-
setHost
public void setHost(java.lang.String newHostValue) throws com.apama.util.CompoundExceptionSetter for the host property. This is the name of the host on which the remote server to be monitored 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:
setHostin interfaceBaseClientInterface- Parameters:
newHostValue- The new value for the Host property.- Throws:
com.apama.util.CompoundException- 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 correlator to be remote server is listening.- Specified by:
getPortin interfaceBaseClientInterface- Returns:
- Port number on which the correlator to be remote server is listening.
-
setPort
public void setPort(int newPortValue) throws com.apama.util.CompoundExceptionSetter for the port property. This is the port number on which the remote server 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:
setPortin interfaceBaseClientInterface- Parameters:
newPortValue- The new value for the Port property.- Throws:
com.apama.util.CompoundException- Thrown if any exceptions occur in the Client SDK.
-
getProcessName
public java.lang.String getProcessName()
Get the process Name in use This is the process name in use for this bean- Specified by:
getProcessNamein interfaceBaseClientInterface- Returns:
- Process name in use
-
setProcessName
public void setProcessName(java.lang.String newProcessName) throws com.apama.util.CompoundExceptionSetter for the process Name This is the process name property 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:
setProcessNamein interfaceBaseClientInterface- Parameters:
newProcessName- The new value for the process name property.- Throws:
com.apama.util.CompoundException- Thrown if any exceptions occur in the Client SDK.
-
isBeanConnected
public boolean isBeanConnected()
Another name for the getBeanConnected() method.- Specified by:
isBeanConnectedin interfaceBaseClientInterface- Returns:
- true if the bean has a connection to an 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 PingBean has a valid instance of the Pingable interface.- Specified by:
getBeanConnectedin interfaceBaseClientInterface- Returns:
- true if the bean has a connection to a remote server, false if not.
-
isPolling
public boolean isPolling()
Determine if the connection is being tested in a background thread. Returns true if the background polling thread exists.
-
getConnectionPollingInterval
public int getConnectionPollingInterval()
Get the polling interval (in milliseconds) for the internal connection test thread.- Specified by:
getConnectionPollingIntervalin interfaceBaseClientInterface- 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:
setConnectionPollingIntervalin interfaceBaseClientInterface- Parameters:
milliseconds- the current interval in milliseconds
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener.- Specified by:
removePropertyChangeListenerin interfaceBaseClientInterface- 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:
addPropertyChangeListenerin interfaceBaseClientInterface- 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:
removePropertyChangeListenerin interfaceBaseClientInterface- 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:
addPropertyChangeListenerin interfaceBaseClientInterface- Parameters:
propertyName- the name of the property to listen on.listener- the listener to be added.
-
-