Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Created IConnectionAdapter and IConnectionClient.
Browse files Browse the repository at this point in the history
Made ConnectionAdapter an implementation of IConnectionAdapter.
Created a basic implementation of IConnectionClient (the code comes from
the current version of VisItPlot).

Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Mar 4, 2015
1 parent f2d4a42 commit 4062bd8
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 29 deletions.
Expand Up @@ -44,7 +44,8 @@
* @param <T>
* The type of the connection object.
*/
public abstract class ConnectionAdapter<T> extends ICEObject {
public abstract class ConnectionAdapter<T> extends ICEObject implements
IConnectionAdapter<T> {

/**
* The current connection managed by this adapter.
Expand All @@ -71,6 +72,15 @@ public ConnectionAdapter() {
}

// ---- Connect, Disconnect, and implementations. ---- //
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.connections.IConnectionAdapter#connect()
*/
public boolean connect() {
return connect(false);
}

/**
* Connects to the associated {@link #connection} if not already connected
* or connecting.
Expand Down Expand Up @@ -160,6 +170,16 @@ public void run() {
*/
protected abstract T openConnection();

/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.connections.IConnectionAdapter#disconnect()
*/
public boolean disconnect() {
return disconnect(false);
}

/**
* Disconnects the associated {@link #connection} if not already
* disconnected.
Expand Down Expand Up @@ -297,59 +317,51 @@ private void setState(ConnectionState state) {
}

// ---- Public Methods ---- //
/**
* Gets the connection managed by this adapter.
/*
* (non-Javadoc)
*
* @return The associated connection.
* @see
* org.eclipse.ice.viz.service.connections.IConnectionAdapter#getConnection
* ()
*/
public T getConnection() {
return connection;
}

/**
* Gets the connection property corresponding to the specified key.
/*
* (non-Javadoc)
*
* @param key
* The key or ID of the required connection property.
* @return The value of the connection property, or {@code null} if the key
* did not exist.
* @see org.eclipse.ice.viz.service.connections.IConnectionAdapter#
* getConnectionProperty(java.lang.String)
*/
public String getConnectionProperty(String key) {
return connectionProperties.get(key);
}

/**
* Gets the key currently associated with this connection. The value is
* usually maintained by a connection manager.
/*
* (non-Javadoc)
*
* @return The connection key.
* @see org.eclipse.ice.viz.service.connections.IConnectionAdapter#getKey()
*/
public String getKey() {
return getName();
}

/**
* Gets the current state of the associated connection.
/*
* (non-Javadoc)
*
* @return The current state of the associated connection.
* @see
* org.eclipse.ice.viz.service.connections.IConnectionAdapter#getState()
*/
public ConnectionState getState() {
return state;
}

/**
* Sets the connection's required {@link #connectionProperties properties}
* based on the provided list of {@code Entry}s (usually a row from a
* {@link ConnectionManager}).
* <p>
* The associated connection will <i>not</i> be reset if the connection
* properties have changed.
* </p>
/*
* (non-Javadoc)
*
* @param properties
* The list of new connection properties.
* @return True if the new connection properties were valid and a change
* occurred, false otherwise.
* @see org.eclipse.ice.viz.service.connections.IConnectionAdapter#
* setConnectionProperties(java.util.List)
*/
public abstract boolean setConnectionProperties(List<Entry> properties);

Expand Down
@@ -0,0 +1,51 @@
package org.eclipse.ice.viz.service.connections;

/**
* This class provides a basic implementation of an {@link IConnectionClient}.
*
* @author Jordan Deyton
*
* @param <T>
* The connection's object type.
*/
public abstract class ConnectionClient<T> implements IConnectionClient<T> {

/**
* The current connection adapter associated with this client.
*/
private IConnectionAdapter<T> adapter;

/*
* (non-Javadoc)
*
* @see
* org.eclipse.ice.viz.service.connections.IConnectionClient#setConnection
* (org.eclipse.ice.viz.service.connections.IConnectionAdapter)
*/
public void setConnection(IConnectionAdapter<T> adapter) {
if (adapter != this.adapter) {
if (this.adapter != null) {
this.adapter.unregister(this);
}
this.adapter = adapter;

// Trigger an update.
update(adapter);

// Register for updates from the adapter if possible.
if (adapter != null) {
adapter.register(this);
}
}
return;
}

/**
* Gets the current connection adapter associated with this client.
*
* @return The connection adapter.
*/
protected IConnectionAdapter<T> getConnectionAdapter() {
return adapter;
}
}
@@ -0,0 +1,116 @@
package org.eclipse.ice.viz.service.connections;

import java.util.List;

import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.datastructures.form.Entry;

/**
* This is an interface for adapters that wrap any sort of local or remote
* connection. If provides feedback based on the current state of the connection
* to registered {@link IUpdateableListener}s (see also:
* {@link IConnectionClient}).
*
* @author Jordan Deyton
*
* @param <T>
* The type of the connection object.
*/
public interface IConnectionAdapter<T> extends IUpdateable {

/**
* Connects to the associated connection if not already connected or
* connecting.
* <p>
* <b>Note:</b>This method will not block the caller thread, so it is the
* same as calling {@link #connect(boolean) connect(false)}.
* </p>
*
* @return True if the connection is established upon returning, false
* otherwise.
*/
boolean connect();

/**
* Connects to the associated connection if not already connected or
* connecting.
*
* @param block
* If true, then the calling thread will be blocked until the
* connection succeeds or fails. If false, then the connection
* process will not block the calling thread.
* @return True if the connection is established upon returning, false
* otherwise.
*/
boolean connect(boolean block);

/**
* Disconnects the associated connection if not already disconnected.
* <p>
* <b>Note:</b>This method will not block the caller thread, so it is the
* same as calling {@link #disconnect(boolean) disconnect(false)}.
* </p>
*
* @return True if the connection is closed upon returning, false otherwise.
*/
boolean disconnect();

/**
* Disconnects the associated connection if not already disconnected.
*
* @param block
* If true, then the calling thread will be blocked until the
* disconnection succeeds or fails. If false, then the
* disconnection process will not block the calling thread.
* @return True if the connection is closed upon returning, false otherwise.
*/
boolean disconnect(boolean block);

/**
* Gets the connection managed by this adapter.
*
* @return The associated connection.
*/
T getConnection();

/**
* Gets the connection property corresponding to the specified key.
*
* @param key
* The key or ID of the required connection property.
* @return The value of the connection property, or {@code null} if the key
* did not exist.
*/
String getConnectionProperty(String key);

/**
* Gets the key currently associated with this connection. The value is
* usually maintained by a connection manager.
*
* @return The connection key.
*/
String getKey();

/**
* Gets the current state of the associated connection.
*
* @return The current state of the associated connection.
*/
ConnectionState getState();

/**
* Sets the connection's required properties based on the provided list of
* {@code Entry}s (usually a row from a {@link ConnectionTable}).
* <p>
* The associated connection should <i>not</i> be reset if the connection
* properties have changed.
* </p>
*
* @param properties
* The list of new connection properties.
* @return True if the new connection properties were valid and a change
* occurred, false otherwise.
*/
boolean setConnectionProperties(List<Entry> properties);
}
@@ -0,0 +1,32 @@
package org.eclipse.ice.viz.service.connections;

import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;

/**
* A connection client is a class that can be associated with a single
* {@link IConnectionAdapter}. It registers with the adapter as an
* {@link IUpdateableListener} and is notified when the connection changes via
* its {@link #update(IUpdateable)} method.
*
* @author Jordan Deyton
*
* @param <T>
* The connection object's type.
*/
public interface IConnectionClient<T> extends IUpdateableListener {

/**
* Sets the current connection associated with the client.
* <p>
* <b>Note:</b> Implementations should at least unregister from the
* previously associated connection and register with the new one. It may
* also trigger an update to the client.
* </p>
*
* @param adapter
* The new connection adapter. If {@code null}, the connection
* will be unset and the plot will be cleared.
*/
void setConnection(IConnectionAdapter<T> adapter);

}

0 comments on commit 4062bd8

Please sign in to comment.