org.apache.excalibur.instrument.client
Class InstrumentManagerConnection

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.apache.excalibur.instrument.client.InstrumentManagerConnection
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, org.apache.avalon.framework.logger.LogEnabled
Direct Known Subclasses:
HTTPInstrumentManagerConnection

public abstract class InstrumentManagerConnection
extends javax.swing.JComponent
implements org.apache.avalon.framework.logger.LogEnabled, java.lang.Runnable

A Connection to the remote InstrumentManager.

Since:
4.1
Version:
CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:23 $
Author:
Avalon Development Team
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  boolean m_deleted
           
private  javax.swing.JLabel m_descriptionLabel
           
private  InstrumentClientFrame m_frame
           
private  long m_lastLeaseRenewalTime
           
private  InstrumentManagerConnectionListener[] m_listenerArray
           
private  java.util.List m_listeners
           
private  org.apache.avalon.framework.logger.Logger m_logger
           
private  MaintainedSampleLease[] m_maintainedSampleLeaseArray
           
private  java.util.HashMap m_maintainedSampleLeaseMap
           
private  java.lang.Thread m_runner
           
private  InstrumentSampleFrame[] m_sampleFrameArray
           
private  java.util.Map m_sampleFrames
          Maintain a list of all sample frames which are viewing data in this connection.
private  InstrumentManagerTree m_tree
           
private  InstrumentManagerTreeModel m_treeModel
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
InstrumentManagerConnection()
          Creates a new InstrumentManagerConnection.
 
Method Summary
(package private)  void addInstrumentManagerConnectionListener(InstrumentManagerConnectionListener listener)
          Adds a InstrumentManagerConnectionListener to the list of listeners which receive state updates of the connection.
private  void addSampleFrame(java.lang.String sampleName, InstrumentSampleFrame sampleFrame)
          Adds a single sample frame.
(package private)  void delete()
          Called when the connection should be closed and then deleted along with any frames and resources that are associated with it.
 void enableLogging(org.apache.avalon.framework.logger.Logger logger)
           
(package private)  InstrumentClientFrame getFrame()
          Returns a reference to the client frame.
abstract  InstrumentManagerData getInstrumentManager()
          Returns the Instrument Manager.
(package private)  javax.swing.tree.DefaultMutableTreeNode getInstrumentSampleTreeNode(java.lang.String sampleName)
           
abstract  java.lang.Object getKey()
          Returns the key used to identify this object.
protected  InstrumentManagerConnectionListener[] getListenerArray()
          Get a threadsafe array of the current listeners avoiding synchronization when possible.
protected  org.apache.avalon.framework.logger.Logger getLogger()
           
(package private)  MaintainedSampleLease getMaintainedSampleLease(java.lang.String sampleName)
          Returns a MaintainedSampleLease given a name if the sample is being maintained.
private  MaintainedSampleLease[] getMaintainedSampleLeaseArray()
          Returns a thread save array representation of the MaintainedSampleLeases.
private  InstrumentSampleFrame getSampleFrame(java.lang.String sampleName)
          Returns a sample frame given a sample name.
protected  InstrumentSampleFrame[] getSampleFrameArray()
          Returns a thread save array representation of the InstrumentSampleFrames.
(package private)  InstrumentSampleSnapshotData getSampleSnapshot(java.lang.String sampleName)
          Returns a snapshot of the specified sample.
 java.lang.String getTabTitle()
          Returns the title to display in the tab for the connection.
 java.lang.String getTabTooltip()
          Returns the tooltip to display in the tab for the connection.
 java.lang.String getTitle()
          Returns the title for the connection.
(package private)  InstrumentManagerTreeModel getTreeModel()
          Returns the TreeModel which contains the entire Instrument tree for this connection.
(package private)  void handleLeasedSamples()
          Called once each second by the main worker thread of the client.
(package private)  void hideSampleFrame(InstrumentSampleFrame sampleFrame)
          Called when a Sample Frame is closed.
 void init()
          Called to initialize the connection object.
protected abstract  void invokeGC()
          Invokes GC on the JVM running the InstrumentManager.
abstract  boolean isConnected()
          Returns true if connected.
 boolean isDeleted()
          Returns true once the connection has been deleted.
(package private)  void loadSampleFrame(org.apache.avalon.framework.configuration.Configuration sampleFrameState)
          Loads an InstrumentSampleFrame from a saved state.
 void loadState(org.apache.avalon.framework.configuration.Configuration state)
          Loads the state from a Configuration object.
(package private)  void removeInstrumentManagerConnectionListener(InstrumentManagerConnectionListener listener)
          Removes a InstrumentManagerConnectionListener from the list of listeners which receive state updates of the connection.
private  void removeSampleFrame(java.lang.String sampleName)
          Removes a single sample frame.
 void run()
           
 org.apache.avalon.framework.configuration.Configuration saveState()
          Saves the current state into a Configuration.
(package private)  void setFrame(InstrumentClientFrame frame)
          Stores a reference to the client frame.
(package private)  void showCreateSampleDialog(InstrumentData instrumentData)
          Create a new Sample assigned to the specified instrument data.
(package private)  void startMaintainingSample(java.lang.String instrumentName, int type, long interval, int size, long leaseDuration, java.lang.String description)
          Start maintaining the lease for an instrument sample which already exists.
(package private)  void stopMaintainingSample(java.lang.String sampleName)
          Stop maintaining the lease for an instrument sample which already exists.
 java.lang.String toString()
          Returns a string representation of the connection.
 void update()
          Causes the InstrumentManagerConnection to update itself with the latest data from the server.
 void updateSampleFrames()
          Updates all registered SampleFrames with the latest data from the server.
(package private)  void viewSample(java.lang.String sampleName)
          Displays a frame for the given sample.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_logger

private org.apache.avalon.framework.logger.Logger m_logger

m_treeModel

private InstrumentManagerTreeModel m_treeModel

m_tree

private InstrumentManagerTree m_tree

m_frame

private InstrumentClientFrame m_frame

m_deleted

private boolean m_deleted

m_runner

private java.lang.Thread m_runner

m_descriptionLabel

private javax.swing.JLabel m_descriptionLabel

m_listeners

private final java.util.List m_listeners

m_listenerArray

private InstrumentManagerConnectionListener[] m_listenerArray

m_lastLeaseRenewalTime

private long m_lastLeaseRenewalTime

m_maintainedSampleLeaseMap

private java.util.HashMap m_maintainedSampleLeaseMap

m_maintainedSampleLeaseArray

private MaintainedSampleLease[] m_maintainedSampleLeaseArray

m_sampleFrames

private java.util.Map m_sampleFrames
Maintain a list of all sample frames which are viewing data in this connection.


m_sampleFrameArray

private InstrumentSampleFrame[] m_sampleFrameArray
Constructor Detail

InstrumentManagerConnection

public InstrumentManagerConnection()
Creates a new InstrumentManagerConnection.

Method Detail

enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger logger)
Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled

getLogger

protected org.apache.avalon.framework.logger.Logger getLogger()

run

public void run()
Specified by:
run in interface java.lang.Runnable

setFrame

final void setFrame(InstrumentClientFrame frame)
Stores a reference to the client frame.

Parameters:
frame - The main client frame.

getFrame

final InstrumentClientFrame getFrame()
Returns a reference to the client frame.

Returns:
A reference to the client frame.

init

public void init()
Called to initialize the connection object.


isDeleted

public boolean isDeleted()
Returns true once the connection has been deleted.

Returns:
True if deleted.

getTabTitle

public java.lang.String getTabTitle()
Returns the title to display in the tab for the connection.

Returns:
The tab title.

getTabTooltip

public java.lang.String getTabTooltip()
Returns the tooltip to display in the tab for the connection.

Returns:
The tab tooltip.

getTitle

public java.lang.String getTitle()
Returns the title for the connection.

Returns:
The title.

getKey

public abstract java.lang.Object getKey()
Returns the key used to identify this object.

Returns:
The key used to identify this object.

isConnected

public abstract boolean isConnected()
Returns true if connected.

Returns:
True if connected.

getInstrumentManager

public abstract InstrumentManagerData getInstrumentManager()
Returns the Instrument Manager.

Returns:
The Instrument Manager.

update

public void update()
Causes the InstrumentManagerConnection to update itself with the latest data from the server. Called by the updateConnection method.


invokeGC

protected abstract void invokeGC()
Invokes GC on the JVM running the InstrumentManager.


saveState

public org.apache.avalon.framework.configuration.Configuration saveState()
Saves the current state into a Configuration.

Returns:
The state as a Configuration.

loadState

public void loadState(org.apache.avalon.framework.configuration.Configuration state)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Loads the state from a Configuration object.

Parameters:
state - Configuration object to load state from.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If there were any problems loading the state.

updateSampleFrames

public void updateSampleFrames()
Updates all registered SampleFrames with the latest data from the server. The status of all Sample Frames is also handled by this method, so it must handle disconnected connections and missing or expired samples correctly.


getTreeModel

InstrumentManagerTreeModel getTreeModel()
Returns the TreeModel which contains the entire Instrument tree for this connection.

Returns:
The TreeModel.

getInstrumentSampleTreeNode

javax.swing.tree.DefaultMutableTreeNode getInstrumentSampleTreeNode(java.lang.String sampleName)

addInstrumentManagerConnectionListener

void addInstrumentManagerConnectionListener(InstrumentManagerConnectionListener listener)
Adds a InstrumentManagerConnectionListener to the list of listeners which receive state updates of the connection.

Parameters:
listener - InstrumentManagerConnectionListener to start receiving state updates.

removeInstrumentManagerConnectionListener

void removeInstrumentManagerConnectionListener(InstrumentManagerConnectionListener listener)
Removes a InstrumentManagerConnectionListener from the list of listeners which receive state updates of the connection.

Parameters:
listener - InstrumentManagerConnectionListener to stop receiving state updates.

getListenerArray

protected InstrumentManagerConnectionListener[] getListenerArray()
Get a threadsafe array of the current listeners avoiding synchronization when possible. The contents of the returned array will never change.

Returns:
An array of the currently registered listeners

getSampleSnapshot

InstrumentSampleSnapshotData getSampleSnapshot(java.lang.String sampleName)
Returns a snapshot of the specified sample. If a snapshot can not be returned for any reason, then return null.

Parameters:
Returns - a snapshot of the specified sample.

getSampleFrame

private InstrumentSampleFrame getSampleFrame(java.lang.String sampleName)
Returns a sample frame given a sample name. Caller must synchronize on this connection before calling.

Parameters:
sampleName - Name of the sample requested.
Returns:
A sample frame given a sample name.

addSampleFrame

private void addSampleFrame(java.lang.String sampleName,
                            InstrumentSampleFrame sampleFrame)
Adds a single sample frame. Caller must synchronize on this connection before calling.


removeSampleFrame

private void removeSampleFrame(java.lang.String sampleName)
Removes a single sample frame. Caller must synchronize on this connection before calling.


getSampleFrameArray

protected InstrumentSampleFrame[] getSampleFrameArray()
Returns a thread save array representation of the InstrumentSampleFrames.

Returns:
A thread save array representation of the InstrumentSampleFrames.

loadSampleFrame

void loadSampleFrame(org.apache.avalon.framework.configuration.Configuration sampleFrameState)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Loads an InstrumentSampleFrame from a saved state.

Parameters:
sampleFrameState - Saved state of the frame to load.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If there are any problems with the state.

viewSample

void viewSample(java.lang.String sampleName)
Displays a frame for the given sample.

Parameters:
sampleName - Name of the sample to display.

delete

void delete()
Called when the connection should be closed and then deleted along with any frames and resources that are associated with it.


hideSampleFrame

void hideSampleFrame(InstrumentSampleFrame sampleFrame)
Called when a Sample Frame is closed.


startMaintainingSample

void startMaintainingSample(java.lang.String instrumentName,
                            int type,
                            long interval,
                            int size,
                            long leaseDuration,
                            java.lang.String description)
Start maintaining the lease for an instrument sample which already exists.

Parameters:
instrumentName - The full name of the instrument whose sample is to be created or updated.
type - The type of sample to be created.
interval - Sample interval of the new sample.
size - Number of samples in the new sample.
leaseDuration - Length of the lease to maintain in milliseconds.
description - Description to assign to the new sample.

stopMaintainingSample

void stopMaintainingSample(java.lang.String sampleName)
Stop maintaining the lease for an instrument sample which already exists.


getMaintainedSampleLease

MaintainedSampleLease getMaintainedSampleLease(java.lang.String sampleName)
Returns a MaintainedSampleLease given a name if the sample is being maintained. Otherwise returns null.

Parameters:
sampleName - Name of the sample being requested.
Returns:
A MaintainedSampleLease given a name.

getMaintainedSampleLeaseArray

private MaintainedSampleLease[] getMaintainedSampleLeaseArray()
Returns a thread save array representation of the MaintainedSampleLeases.

Returns:
A thread save array representation of the MaintainedSampleLeases.

handleLeasedSamples

void handleLeasedSamples()
Called once each second by the main worker thread of the client. This method is responsible for maintaining and expiring leased samples.


showCreateSampleDialog

void showCreateSampleDialog(InstrumentData instrumentData)
Create a new Sample assigned to the specified instrument data.

Parameters:
instrumentData - Instrument to add a sample to.

toString

public java.lang.String toString()
Returns a string representation of the connection.

Overrides:
toString in class java.awt.Component