This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created IConnectionAdapter and IConnectionClient.
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
Showing
4 changed files
with
240 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/connections/ConnectionClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...lipse.ice.viz.service/src/org/eclipse/ice/viz/service/connections/IConnectionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
32 changes: 32 additions & 0 deletions
32
...clipse.ice.viz.service/src/org/eclipse/ice/viz/service/connections/IConnectionClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} |