leif 02/03/29 17:30:49
Modified:
instrument-client/src/java/org/apache/avalon/excalibur/instrument/client
InstrumentClientFrame.java
InstrumentManagerConnection.java
InstrumentManagerConnectionListener.java
InstrumentManagerFrame.java
InstrumentSampleFrame.java MenuBar.java
Log:
Add the ability to delete connections and exit the client.
Revision Changes Path
1.4 +113 -19
jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentClientFrame.java
Index: InstrumentClientFrame.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentClientFrame.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InstrumentClientFrame.java 28 Mar 2002 04:06:18 -0000 1.3
+++ InstrumentClientFrame.java 30 Mar 2002 01:30:49 -0000 1.4
@@ -26,12 +26,12 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/03/28 04:06:18 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/03/30 01:30:49 $
* @since 4.1
*/
class InstrumentClientFrame
extends JFrame
- implements Runnable
+ implements Runnable, InstrumentManagerConnectionListener
{
private String m_title;
@@ -81,6 +81,10 @@
}
catch( InterruptedException e )
{
+ if ( m_runner == null )
+ {
+ return;
+ }
}
// Check on the status of all of the connections (Avoid
synchronization)
@@ -127,6 +131,45 @@
}
/*---------------------------------------------------------------
+ * InstrumentManagerConnectionListener Methods
+ *-------------------------------------------------------------*/
+ /**
+ * Called when the connection is opened. May be called more than once
if
+ * the connection to the InstrumentManager is reopened.
+ *
+ * @param connection Connection which was opened.
+ */
+ public void opened( InstrumentManagerConnection connection )
+ {
+ }
+
+ /**
+ * Called when the connection is closed. May be called more than once
if
+ * the connection to the InstrumentManager is reopened.
+ *
+ * @param connection Connection which was closed.
+ */
+ public void closed( InstrumentManagerConnection connection )
+ {
+ }
+
+ /**
+ * Called when the connection is deleted. All references should be
removed.
+ *
+ * @param connection Connection which was deleted.
+ */
+ public void deleted( InstrumentManagerConnection connection )
+ {
+ connection.removeInstrumentManagerConnectionListener( this );
+ String key = connection.getHost() + ":" + connection.getPort();
+ synchronized (m_connections)
+ {
+ m_connections.remove( key );
+ m_connectionArray = null;
+ }
+ }
+
+ /*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
private void init()
@@ -228,28 +271,37 @@
} );
}
- void openInstrumentManagerConnection( String host, int port )
+ void openInstrumentManagerConnection( final String host, final int port )
{
- String key = host + ":" + port;
- synchronized (m_connections)
+ SwingUtilities.invokeLater( new Runnable()
{
- InstrumentManagerConnection connection =
- (InstrumentManagerConnection)m_connections.get( key );
- if ( connection == null )
+ public void run()
{
- connection = new InstrumentManagerConnection( host, port );
- m_connections.put( key, connection );
- m_connectionArray = null;
-
- openInstrumentManagerConnectionFrame( connection );
+ String key = host + ":" + port;
+ synchronized (m_connections)
+ {
+ InstrumentManagerConnection connection =
+ (InstrumentManagerConnection)m_connections.get( key
);
+ if ( connection == null )
+ {
+ connection = new InstrumentManagerConnection( host,
port );
+ m_connections.put( key, connection );
+ m_connectionArray = null;
+
+ connection.addInstrumentManagerConnectionListener(
+ InstrumentClientFrame.this );
+
+ openInstrumentManagerConnectionFrame( connection );
+
+ return;
+ }
+ }
- return;
+ // If we get here show an error that the connection alreay
exists.
+ // Must be done outside the synchronization block.
+ showErrorDialog( "A connection to " + key + " already
exists." );
}
- }
-
- // If we get here show an error that the connection alreay exists.
- // Must be done outside the synchronization block.
- showErrorDialog( "A connection to " + key + " already exists." );
+ } );
}
void openInstrumentManagerConnectionFrame( final
InstrumentManagerConnection connection )
@@ -302,5 +354,47 @@
t.getMessage() +
"</font></body></html>",
m_title + " Error",
JOptionPane.ERROR_MESSAGE );
}
+
+
+ /**
+ * Shutdown the InstrumentClient.
+ */
+ private void shutdown()
+ {
+ // Stop the runner.
+ m_runner.interrupt();
+ m_runner = null;
+
+ // Close all connections cleanly.
+ InstrumentManagerConnection[] connections =
getInstrumentManagerConnections();
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ connections[i].delete();
+ }
+
+ // Kill the JVM.
+ System.exit( 1 );
+ }
+
+ /*---------------------------------------------------------------
+ * Menu Callback Methods
+ *-------------------------------------------------------------*/
+ /**
+ * File-Exit callback.
+ */
+ void fileExit()
+ {
+ SwingUtilities.invokeLater( new Runnable()
+ {
+ public void run()
+ {
+ shutdown();
+ }
+ } );
+ }
+
+ /**
+ * File-Exit callback.
+ */
}
1.4 +73 -25
jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentManagerConnection.java
Index: InstrumentManagerConnection.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentManagerConnection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- InstrumentManagerConnection.java 28 Mar 2002 04:06:18 -0000 1.3
+++ InstrumentManagerConnection.java 30 Mar 2002 01:30:49 -0000 1.4
@@ -23,7 +23,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/03/28 04:06:18 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/03/30 01:30:49 $
* @since 4.1
*/
class InstrumentManagerConnection
@@ -36,6 +36,7 @@
private InstrumentManagerClient m_manager;
private ArrayList m_listeners = new ArrayList();
+ private InstrumentManagerConnectionListener[] m_listenerArray;
/*---------------------------------------------------------------
* Constructors
@@ -105,12 +106,18 @@
"InstrumentManagerClient" );
m_closed = false;
-
- // Notify the listeners.
- for ( Iterator iter = m_listeners.iterator(); iter.hasNext(); )
- {
- ((InstrumentManagerConnectionListener)iter.next()).opened(
m_host, m_port);
- }
+ }
+
+ // Notify the listeners.
+ InstrumentManagerConnectionListener[] listeners = m_listenerArray;
+ if ( listeners == null )
+ {
+ listeners = updateListenerArray();
+ }
+
+ for ( int i = 0; i < listeners.length; i++ )
+ {
+ listeners[i].opened( this );
}
}
@@ -131,13 +138,23 @@
}
}
+ /**
+ * Returns true if the connection is currently closed.
+ *
+ * @return True if the connection is currently closed.
+ */
public boolean isClosed()
{
return m_closed;
}
+ /**
+ * Closes the connection, but keeps it around. If the remote instrument
manager
+ * is running the connection will reopen itself.
+ */
public void close()
{
+ System.out.println("InstrumentManagerConnection.close()");
synchronized (this)
{
if ( !m_closed )
@@ -146,31 +163,58 @@
m_manager = null;
m_altrmiFactory.close();
m_altrmiFactory = null;
+ // Uncomment this when it gets implemented.
+ // m_altrmiHostContext.close();
m_altrmiHostContext = null;
-
- // Notify the listeners.
- for ( Iterator iter = m_listeners.iterator();
iter.hasNext(); )
- {
-
((InstrumentManagerConnectionListener)iter.next()).closed( m_host, m_port);
- }
}
}
+
+ // Notify the listeners.
+ InstrumentManagerConnectionListener[] listeners = m_listenerArray;
+ if ( listeners == null )
+ {
+ listeners = updateListenerArray();
+ }
+
+ for ( int i = 0; i < listeners.length; i++ )
+ {
+ listeners[i].closed( this );
+ }
}
- public void dispose()
+ /**
+ * Called when the connection should be closed and then deleted along
with
+ * any frames and resources that are associated with it.
+ */
+ void delete()
{
- synchronized (this)
+ close();
+
+ // Notify the listeners.
+ InstrumentManagerConnectionListener[] listeners = m_listenerArray;
+ if ( listeners == null )
{
- if ( !isClosed() )
- {
- close();
- }
-
- // Notify the listeners.
- for ( Iterator iter = m_listeners.iterator(); iter.hasNext(); )
- {
- ((InstrumentManagerConnectionListener)iter.next()).disposed(
m_host, m_port);
- }
+ listeners = updateListenerArray();
+ }
+
+ for ( int i = 0; i < listeners.length; i++ )
+ {
+ listeners[i].deleted( this );
+ }
+ }
+
+ /**
+ * Updates the cached array of listeners so that it can be used without
synchronization.
+ *
+ * @returns An array of listeners. Will never be null and is thread
safe.
+ */
+ private InstrumentManagerConnectionListener[] updateListenerArray()
+ {
+ synchronized(this)
+ {
+ m_listenerArray = new InstrumentManagerConnectionListener[
m_listeners.size() ];
+ m_listeners.toArray( m_listenerArray );
+ return m_listenerArray;
}
}
@@ -187,6 +231,8 @@
}
catch ( AltrmiInvocationException e )
{
+ System.out.println("Ping Failed.");
+ e.printStackTrace();
// Socket was closed.
close();
}
@@ -199,6 +245,7 @@
synchronized (this)
{
m_listeners.add( listener );
+ m_listenerArray = null;
}
}
@@ -207,6 +254,7 @@
synchronized (this)
{
m_listeners.remove( listener );
+ m_listenerArray = null;
}
}
}
1.2 +8 -11
jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentManagerConnectionListener.java
Index: InstrumentManagerConnectionListener.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentManagerConnectionListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InstrumentManagerConnectionListener.java 26 Mar 2002 11:32:24 -0000
1.1
+++ InstrumentManagerConnectionListener.java 30 Mar 2002 01:30:49 -0000
1.2
@@ -10,7 +10,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/03/26 11:32:24 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/03/30 01:30:49 $
* @since 4.1
*/
interface InstrumentManagerConnectionListener
@@ -19,26 +19,23 @@
* Called when the connection is opened. May be called more than once
if
* the connection to the InstrumentManager is reopened.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was opened.
*/
- void opened( String host, int port );
+ void opened( InstrumentManagerConnection connection );
/**
* Called when the connection is closed. May be called more than once
if
* the connection to the InstrumentManager is reopened.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was closed.
*/
- void closed( String host, int port );
+ void closed( InstrumentManagerConnection connection );
/**
- * Called when the connection is disposed. All references should be
removed.
+ * Called when the connection is deleted. All references should be
removed.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was deleted.
*/
- void disposed( String host, int port );
+ void deleted( InstrumentManagerConnection connection );
}
1.3 +8 -11
jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentManagerFrame.java
Index: InstrumentManagerFrame.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentManagerFrame.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InstrumentManagerFrame.java 28 Mar 2002 04:06:18 -0000 1.2
+++ InstrumentManagerFrame.java 30 Mar 2002 01:30:49 -0000 1.3
@@ -20,7 +20,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/03/28 04:06:18 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/03/30 01:30:49 $
* @since 4.1
*/
class InstrumentManagerFrame
@@ -101,10 +101,9 @@
* Called when the connection is opened. May be called more than once
if
* the connection to the InstrumentManager is reopened.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was opened.
*/
- public void opened( String host, int port )
+ public void opened( InstrumentManagerConnection connection )
{
// Status changed, so reinitialize the frame.
init();
@@ -114,22 +113,20 @@
* Called when the connection is closed. May be called more than once
if
* the connection to the InstrumentManager is reopened.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was closed.
*/
- public void closed( String host, int port )
+ public void closed( InstrumentManagerConnection connection )
{
// Status changed, so reinitialize the frame.
init();
}
/**
- * Called when the connection is disposed. All references should be
removed.
+ * Called when the connection is deleted. All references should be
removed.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was deleted.
*/
- public void disposed( String host, int port )
+ public void deleted( InstrumentManagerConnection connection )
{
hideFrame();
}
1.3 +8 -11
jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentSampleFrame.java
Index: InstrumentSampleFrame.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/InstrumentSampleFrame.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InstrumentSampleFrame.java 28 Mar 2002 04:06:18 -0000 1.2
+++ InstrumentSampleFrame.java 30 Mar 2002 01:30:49 -0000 1.3
@@ -31,7 +31,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/03/28 04:06:18 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/03/30 01:30:49 $
* @since 4.1
*/
class InstrumentSampleFrame
@@ -121,10 +121,9 @@
* Called when the connection is opened. May be called more than once
if
* the connection to the InstrumentManager is reopened.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was opened.
*/
- public void opened( String host, int port )
+ public void opened( InstrumentManagerConnection connection )
{
// Status changed, so reinitialize the frame.
init();
@@ -134,22 +133,20 @@
* Called when the connection is closed. May be called more than once
if
* the connection to the InstrumentManager is reopened.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was closed.
*/
- public void closed( String host, int port )
+ public void closed( InstrumentManagerConnection connection )
{
// Status changed, so reinitialize the frame.
init();
}
/**
- * Called when the connection is disposed. All references should be
removed.
+ * Called when the connection is deleted. All references should be
removed.
*
- * @param host Host of the connection.
- * @param host Port of the connection.
+ * @param connection Connection which was deleted.
*/
- public void disposed( String host, int port )
+ public void deleted( InstrumentManagerConnection connection )
{
hideFrame();
}
1.4 +54 -5
jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/MenuBar.java
Index: MenuBar.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/avalon/excalibur/instrument/client/MenuBar.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MenuBar.java 28 Mar 2002 04:06:18 -0000 1.3
+++ MenuBar.java 30 Mar 2002 01:30:49 -0000 1.4
@@ -30,7 +30,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/03/28 04:06:18 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/03/30 01:30:49 $
* @since 4.1
*/
public class MenuBar
@@ -71,7 +71,8 @@
{
m_menuFile = new JMenu( "File" );
m_menuFile.setMnemonic( 'F' );
-
+
+
// Clear
Action newAction = new AbstractAction( "New" )
{
@@ -83,7 +84,8 @@
JMenuItem newItem = new JMenuItem( newAction );
newItem.setMnemonic( 'N' );
m_menuFile.add( newItem );
-
+
+
// Open
Action openAction = new AbstractAction( "Open ..." )
{
@@ -95,7 +97,12 @@
JMenuItem open = new JMenuItem( openAction );
open.setMnemonic( 'O' );
m_menuFile.add( open );
-
+
+
+ // Seperator
+ m_menuFile.addSeparator();
+
+
// Save
Action saveAction = new AbstractAction( "Save" )
{
@@ -107,7 +114,8 @@
JMenuItem save = new JMenuItem( saveAction );
save.setMnemonic( 'S' );
m_menuFile.add( save );
-
+
+
// Save As
Action saveAsAction = new AbstractAction( "Save As ..." )
{
@@ -119,7 +127,24 @@
JMenuItem saveAs = new JMenuItem( saveAsAction );
saveAs.setMnemonic( 'A' );
m_menuFile.add( saveAs );
+
+
+ // Seperator
+ m_menuFile.addSeparator();
+
+ // Exit
+ Action exitAction = new AbstractAction( "Exit" )
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ m_frame.fileExit();
+ }
+ };
+ JMenuItem exit = new JMenuItem( exitAction );
+ exit.setMnemonic( 'X' );
+ m_menuFile.add( exit );
+
return m_menuFile;
}
@@ -219,6 +244,7 @@
boolean showAll = m_menuItemShowUnconfigured.getState();
+ // Details
Action detailAction = new AbstractAction( "Details..." )
{
public void actionPerformed( ActionEvent event )
@@ -236,6 +262,29 @@
detailItem.setMnemonic( 'D' );
managerMenu.add( detailItem );
+
+ // Delete
+ Action deleteAction = new AbstractAction( "Delete" )
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ JMenuItem item = (JMenuItem)event.getSource();
+ Action action = item.getAction();
+
+ InstrumentManagerConnection connection =
+ (InstrumentManagerConnection)action.getValue(
"connection" );
+
+ connection.delete();
+ }
+ };
+ deleteAction.putValue( "connection", connection );
+
+ JMenuItem deleteItem = new JMenuItem( deleteAction );
+ deleteItem.setMnemonic( 'I' );
+ managerMenu.add( deleteItem );
+
+
+ // Instrument menu items
try
{
InstrumentManagerClient manager =
connection.getInstrumentManagerClient();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>