From: jprocter Date: Tue, 14 Mar 2006 18:25:13 +0000 (+0000) Subject: extended clientfactory interface for session discovery and default session connection X-Git-Tag: Release_0.2~343 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dc683273ee74325ad1701f0497297ee5006f2ef3;p=vamsas.git extended clientfactory interface for session discovery and default session connection git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@177 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/IClientFactory.java b/src/org/vamsas/client/IClientFactory.java index 5f203ef..564782a 100644 --- a/src/org/vamsas/client/IClientFactory.java +++ b/src/org/vamsas/client/IClientFactory.java @@ -18,8 +18,9 @@ public interface IClientFactory { /** * Create a new Vorba Session * @param applicationHandle is the application's VAMSAS handle string + * @throws NoDefaultSessionException if more than one session exists that the client may connect to */ - IClient getIClient(ClientHandle applicationHandle); + IClient getIClient(ClientHandle applicationHandle) throws NoDefaultSessionException; /** * returns new Vorba for a given session. * @param applicationHandle @@ -40,8 +41,16 @@ public interface IClientFactory { * @param applicationHandle * @param userId * @return + * @throws NoDefaultSessionException if more than one session exists that the client may connect to */ - IClient getIClient(ClientHandle applicationHandle, UserHandle userId); + IClient getIClient(ClientHandle applicationHandle, UserHandle userId) throws NoDefaultSessionException; + /** + * enumerate the active sessions this IClientFactory instance knows about. + * Can be used by caller to pick a session on catching a NoDefaultSessionException. + * LATER: Define interface for discovering more information about a session (so it can be presented to a user in a meaningful way) + * @return possibly empty array of sessionUrn strings + */ + public String[] getCurrentSessions(); } diff --git a/src/org/vamsas/client/NoDefaultSessionException.java b/src/org/vamsas/client/NoDefaultSessionException.java new file mode 100644 index 0000000..bfee0e6 --- /dev/null +++ b/src/org/vamsas/client/NoDefaultSessionException.java @@ -0,0 +1,46 @@ +/** + * + */ +package org.vamsas.client; + +/** + * @author jimp + * Raised if an IClient instance is requested without + * specifying a particular vamsas session handle + * when more than one candidate session exists. + */ +public class NoDefaultSessionException extends Exception { + + /** + * + */ + public NoDefaultSessionException() { + super("No Default Session Defined"); + } + + /** + * @param message + */ + public NoDefaultSessionException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + /** + * @param cause + */ + public NoDefaultSessionException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + /** + * @param message + * @param cause + */ + public NoDefaultSessionException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/org/vamsas/client/simpleclient/SimpleClientFactory.java b/src/org/vamsas/client/simpleclient/SimpleClientFactory.java index c6d1687..d3148d7 100644 --- a/src/org/vamsas/client/simpleclient/SimpleClientFactory.java +++ b/src/org/vamsas/client/simpleclient/SimpleClientFactory.java @@ -8,6 +8,7 @@ import org.apache.commons.logging.LogFactory; import org.vamsas.client.ClientHandle; import org.vamsas.client.IClient; import org.vamsas.client.IClientFactory; +import org.vamsas.client.NoDefaultSessionException; import org.vamsas.client.UserHandle; /** @@ -42,10 +43,18 @@ public class SimpleClientFactory implements IClientFactory { throw(new IOException("Cannot read and write to a directory called "+path)); } } + + /* (non-Javadoc) + * @see org.vamsas.client.IClientFactory#getCurrentSessions() + */ + public String[] getCurrentSessions() { + // TODO look in the arena and enumerate session handles for return. + return new String[] {}; + } /* (non-Javadoc) * @see org.vamsas.client.IClientFactory#getIClient(org.vamsas.client.ClientHandle) */ - public IClient getIClient(ClientHandle applicationHandle) { + public IClient getIClient(ClientHandle applicationHandle) throws NoDefaultSessionException { // create a new session // register new ClientHandle in session // create SimpleClient instance @@ -78,7 +87,7 @@ public class SimpleClientFactory implements IClientFactory { /* (non-Javadoc) * @see org.vamsas.client.IClientFactory#getIClient(org.vamsas.client.ClientHandle, org.vamsas.client.UserHandle) */ - public IClient getIClient(ClientHandle applicationHandle, UserHandle userId) { + public IClient getIClient(ClientHandle applicationHandle, UserHandle userId) throws NoDefaultSessionException { // create new session // register SimpleClient and UserHandles in session // create client instance