Package omero
Class client
- java.lang.Object
-
- omero.client
-
public class client extends java.lang.Object
Central client-side blitz entry point. This class uses solely Ice functionality to provide access to blitz (as opposed to also using Spring) and should be in sync with the OmeroPy omero.client class as well as the OmeroCpp omero::client class. In order to more closely map the destructors in Python and C++, this class keeps a collection ofclient
instances, which are destroyed on program termination. Typical usage:omero.client client = new omero.client(); // Uses ICE_CONFIG omero.client client = new omero.client(host); // Defines "omero.host" omero.client client = new omero.client(host, port); // Defines "omero.host" and "omero.port"
For more information, see https://trac.openmicroscopy.org.uk/ome/wiki/ClientDesign- Since:
- 3.0-Beta3
-
-
Constructor Summary
Constructors Constructor Description client()
Callsclient(Ice.InitializationData)
with a newInitializationData
client(Ice.InitializationData id)
Creates anCommunicator
from aInitializationData
instance.client(java.io.File... files)
Creates anCommunicator
from multiple files.client(java.lang.String host)
Creates anCommunicator
pointing at the given server using theServer.DEFAULT_PORT
.client(java.lang.String[] args)
Callsclient(String[], Ice.InitializationData)
with a newInitializationData
client(java.lang.String[] args, Ice.InitializationData id)
Creates anCommunicator
from command-line arguments.client(java.lang.String host, int port)
Creates anCommunicator
pointing at the given server with the non-standard port.client(java.util.Map p)
Creates anCommunicator
from aMap
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
__del__()
Calls closeSession() and ignores any exceptions.void
closeSession()
Closes the session and nulls out the communicator.client
createClient(boolean secure)
Creates a possibly insecureclient
instance and callsjoinSession(String)
using the currentsession id
.ServiceFactoryPrx
createSession()
CallscreateSession(String, String)
with null valuesServiceFactoryPrx
createSession(java.lang.String username, java.lang.String password)
Performs the actual logic of logging in, which is done via thegetRouter(Ice.Communicator)
.void
download(long fileId, java.io.File file)
void
download(long fileId, java.io.File file, int blockSize)
void
enableKeepAlive(int seconds)
Resets the "omero.keep_alive" property on the currentCommunicator
which is used on initialization to determine the time-period betweenchecks
.protected ISessionPrx
env()
Helper method to access session environmentprotected static java.lang.String
filesToString(java.io.File... files)
Ice.ObjectAdapter
getAdapter()
java.lang.String
getCategory()
Returns the category which should be used for all callbacks passed to the server.Ice.Communicator
getCommunicator()
Returns theCommunicator
for this instance or throws an exception if null.int
getDefaultBlockSize()
Returns the user-configured setting for "omero.block_size" orDEFAULTBLOCKSIZE
if none is set.Ice.ImplicitContext
getImplicitContext()
Returns theImplicitContext
which defines what properties will be sent on every method invocation.RType
getInput(java.lang.String key)
Retrieves an item from the "input" shared (session) memory.java.util.List<java.lang.String>
getInputKeys()
Returns a list of keys for all items in the "input" shared (session) memoryRType
getOutput(java.lang.String key)
Retrieves an item from the "output" shared (session) memory.java.util.List<java.lang.String>
getOutputKeys()
Returns a list of keys for all items in the "output" shared (session) memoryIce.Properties
getProperties()
Returns theactive properties
for this instance.java.lang.String
getProperty(java.lang.String key)
Returns the property value for this key or the empty string if none.java.util.Map<java.lang.String,java.lang.String>
getPropertyMap()
Returns all properties which are prefixed with "omero." or "Ice." using the Properties fromgetProperties()
.java.util.Map<java.lang.String,java.lang.String>
getPropertyMap(Ice.Properties properties)
Returns all properties which are prefixed with "omero." or "Ice."static Glacier2.RouterPrx
getRouter(Ice.Communicator comm)
Acquires thedefault router
, and throws an exception if it is not of type {Glacier2.RouterPrx}.ServiceFactoryPrx
getSession()
Returns the current active session or throws an exception if none has beencreated
since the lastcloseSession()
java.lang.String
getSessionId()
Returns the UUID for the current session without making a remote call.java.util.List<StatefulServiceInterfacePrx>
getStatefulServices()
Returns all activeStatefulServiceInterface
proxies.boolean
isSecure()
Specifies whether or not this client was created via a call tocreateClient(boolean)
with a boolean of false.ServiceFactoryPrx
joinSession(java.lang.String session)
Uses the given session uuid as name and password to rejoin a running session.int
killSession()
Calls ISession.closeSession(omero.model.Session) until the returned reference count is greater than zero.void
onHeartbeat(java.lang.Runnable runnable)
void
onSessionClosed(java.lang.Runnable runnable)
void
onShutdown(java.lang.Runnable runnable)
protected java.lang.String
parseAndSetInt(Ice.InitializationData data, java.lang.String key, int newValue)
void
setAgent(java.lang.String agent)
Sets theuser agent
string for this client.boolean
setFastShutdown(boolean fastShutdown)
Sets thefastShutdown
flag.void
setInput(java.lang.String key, RType value)
Sets an item in the "input" shared (session) memory under the given name.void
setIP(java.lang.String ip)
Sets theuser ip
string for this client.void
setOutput(java.lang.String key, RType value)
Sets an item in the "output" shared (session) memory under the given name.java.lang.String
sha1(java.io.File file)
Calculates the local sha1 for a file.OriginalFile
upload(java.io.File file)
OriginalFile
upload(java.io.File file, OriginalFile fileObject)
OriginalFile
upload(java.io.File file, OriginalFile fileObject, java.lang.Integer blockSize)
Utility method to upload a file to the server
-
-
-
Constructor Detail
-
client
public client()
Callsclient(Ice.InitializationData)
with a newInitializationData
-
client
public client(Ice.InitializationData id)
Creates anCommunicator
from aInitializationData
instance. Cannot be null.- Parameters:
id
- the Ice initialization data
-
client
public client(java.lang.String host)
Creates anCommunicator
pointing at the given server using theServer.DEFAULT_PORT
.- Parameters:
host
- the server host name
-
client
public client(java.lang.String host, int port)
Creates anCommunicator
pointing at the given server with the non-standard port.- Parameters:
host
- the server host nameport
- the server port number
-
client
public client(java.lang.String[] args)
Callsclient(String[], Ice.InitializationData)
with a newInitializationData
- Parameters:
args
- command-line arguments
-
client
public client(java.lang.String[] args, Ice.InitializationData id)
Creates anCommunicator
from command-line arguments. These are parsed via Ice.Properties.parseIceCommandLineOptions(args) and Ice.Properties.parseCommandLineOptions("omero", args)- Parameters:
args
- command-line argumentsid
- the Ice initialization data
-
client
public client(java.io.File... files)
Creates anCommunicator
from multiple files.- Parameters:
files
- files from which to load properties
-
client
public client(java.util.Map p)
Creates anCommunicator
from aMap
instance. TheString
representation of each member is added to theProperties
under theString
representation of the key.- Parameters:
p
- properties
-
-
Method Detail
-
setFastShutdown
public boolean setFastShutdown(boolean fastShutdown)
Sets thefastShutdown
flag. By setting this to true, you will prevent proper clean up. This should only be used in the case of network loss (or similar).- Parameters:
fastShutdown
- if shutdown should be fast- Returns:
- the previous value of this property
-
setAgent
public void setAgent(java.lang.String agent)
Sets theuser agent
string for this client. Every session creation will be passed this argument. Finding open sessions with the same agent can be done viaISessionPrx.getMyOpenAgentSessions(String)
.- Parameters:
agent
- the user agent for sessions
-
setIP
public void setIP(java.lang.String ip)
Sets theuser ip
string for this client. Every session creation will be passed this argument. Finding open sessions with the same agent can be done viaISessionPrx.getMyOpenAgentSessions(String)
.- Parameters:
ip
- the user IP address
-
isSecure
public boolean isSecure()
Specifies whether or not this client was created via a call tocreateClient(boolean)
with a boolean of false. If insecure, then all remote calls will use the insecure connection defined by the server.- Returns:
- if the client's remote calls are secure
-
createClient
public client createClient(boolean secure) throws ServerError, Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException
Creates a possibly insecureclient
instance and callsjoinSession(String)
using the currentsession id
. If secure is false, then first the "omero.router.insecure" configuration property is retrieved from the server and used as the value of "Ice.Default.Router" for the new client. Any exception thrown during creation is passed on to the caller. Note: detachOnDestroy has NOT been called on the session in the returned client. Clients are responsible for doing this immediately if such desired.- Throws:
ServerError
Glacier2.CannotCreateSessionException
Glacier2.PermissionDeniedException
-
__del__
public void __del__()
Calls closeSession() and ignores any exceptions. Equivalent to OmeroPy's __del__ or OmeroCpp's omero::client::~client()
-
getCommunicator
public Ice.Communicator getCommunicator()
Returns theCommunicator
for this instance or throws an exception if null.- Returns:
- this client's
Communicator
-
getAdapter
public Ice.ObjectAdapter getAdapter()
-
getSession
public ServiceFactoryPrx getSession()
Returns the current active session or throws an exception if none has beencreated
since the lastcloseSession()
- Returns:
- the current active session
-
getSessionId
public java.lang.String getSessionId()
Returns the UUID for the current session without making a remote call. UsesgetSession()
internally and will throw an exception if no session is active.- Returns:
- the current session's UUID
-
getCategory
public java.lang.String getCategory()
Returns the category which should be used for all callbacks passed to the server.- Returns:
- the category for callbacks
-
getImplicitContext
public Ice.ImplicitContext getImplicitContext()
Returns theImplicitContext
which defines what properties will be sent on every method invocation.- Returns:
- the
ImplicitContext
-
getProperties
public Ice.Properties getProperties()
Returns theactive properties
for this instance.- Returns:
- the active properties
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Returns the property value for this key or the empty string if none.- Parameters:
key
- a property key- Returns:
- the key's value or the empty string if none
-
getPropertyMap
public java.util.Map<java.lang.String,java.lang.String> getPropertyMap()
Returns all properties which are prefixed with "omero." or "Ice." using the Properties fromgetProperties()
.- Returns:
- the "omero." and "Ice." properties
-
getPropertyMap
public java.util.Map<java.lang.String,java.lang.String> getPropertyMap(Ice.Properties properties)
Returns all properties which are prefixed with "omero." or "Ice."- Parameters:
properties
- some Ice properties- Returns:
- the "omero." and "Ice." properties
-
getDefaultBlockSize
public int getDefaultBlockSize()
Returns the user-configured setting for "omero.block_size" orDEFAULTBLOCKSIZE
if none is set.- Returns:
- the block size (in bytes)
-
joinSession
public ServiceFactoryPrx joinSession(java.lang.String session) throws Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException, ServerError
Uses the given session uuid as name and password to rejoin a running session.- Throws:
Glacier2.CannotCreateSessionException
Glacier2.PermissionDeniedException
ServerError
-
createSession
public ServiceFactoryPrx createSession() throws Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException, ServerError
CallscreateSession(String, String)
with null values- Throws:
Glacier2.CannotCreateSessionException
Glacier2.PermissionDeniedException
ServerError
-
createSession
public ServiceFactoryPrx createSession(java.lang.String username, java.lang.String password) throws Glacier2.CannotCreateSessionException, Glacier2.PermissionDeniedException, ServerError
Performs the actual logic of logging in, which is done via thegetRouter(Ice.Communicator)
. Disallows an extantServiceFactoryPrx
and tries to re-create a nullCommunicator
. A null or empty username will throw an exception, but an empty password is allowed.- Throws:
Glacier2.CannotCreateSessionException
Glacier2.PermissionDeniedException
ServerError
-
getRouter
public static Glacier2.RouterPrx getRouter(Ice.Communicator comm)
Acquires thedefault router
, and throws an exception if it is not of type {Glacier2.RouterPrx}. Also sets theImplicitContext
on the router proxy.- Parameters:
comm
- the Ice communicator- Returns:
- the communicator's router
-
enableKeepAlive
public void enableKeepAlive(int seconds)
Resets the "omero.keep_alive" property on the currentCommunicator
which is used on initialization to determine the time-period betweenchecks
.
-
getStatefulServices
public java.util.List<StatefulServiceInterfacePrx> getStatefulServices() throws ServerError
Returns all activeStatefulServiceInterface
proxies. This can be used to call close before calling setSecurityContext.- Throws:
ServerError
-
closeSession
public void closeSession()
Closes the session and nulls out the communicator. This is required by an Ice bug.- See Also:
- 2370 Ice Ping Error
-
killSession
public int killSession()
Calls ISession.closeSession(omero.model.Session) until the returned reference count is greater than zero. The number of invocations is returned. If ISession.closeSession() cannot be called, -1 is returned.
-
sha1
public java.lang.String sha1(java.io.File file)
Calculates the local sha1 for a file.- Parameters:
file
- a local file- Returns:
- the file's SHA-1 hexadecimal digest
-
upload
public OriginalFile upload(java.io.File file) throws ServerError, java.io.IOException
- Throws:
ServerError
java.io.IOException
-
upload
public OriginalFile upload(java.io.File file, OriginalFile fileObject) throws ServerError, java.io.IOException
- Throws:
ServerError
java.io.IOException
-
upload
public OriginalFile upload(java.io.File file, OriginalFile fileObject, java.lang.Integer blockSize) throws ServerError, java.io.IOException
Utility method to upload a file to the server- Parameters:
file
- Cannot be null.fileObject
- Can be null.blockSize
- Can be null.- Throws:
ServerError
java.io.IOException
-
download
public void download(long fileId, java.io.File file) throws ServerError, java.io.IOException
- Throws:
ServerError
java.io.IOException
-
download
public void download(long fileId, java.io.File file, int blockSize) throws ServerError, java.io.IOException
- Throws:
ServerError
java.io.IOException
-
getInput
public RType getInput(java.lang.String key) throws ServerError
Retrieves an item from the "input" shared (session) memory.- Throws:
ServerError
-
getOutput
public RType getOutput(java.lang.String key) throws ServerError
Retrieves an item from the "output" shared (session) memory.- Throws:
ServerError
-
setInput
public void setInput(java.lang.String key, RType value) throws ServerError
Sets an item in the "input" shared (session) memory under the given name.- Throws:
ServerError
-
setOutput
public void setOutput(java.lang.String key, RType value) throws ServerError
Sets an item in the "output" shared (session) memory under the given name.- Throws:
ServerError
-
getInputKeys
public java.util.List<java.lang.String> getInputKeys() throws ServerError
Returns a list of keys for all items in the "input" shared (session) memory- Throws:
ServerError
-
getOutputKeys
public java.util.List<java.lang.String> getOutputKeys() throws ServerError
Returns a list of keys for all items in the "output" shared (session) memory- Throws:
ServerError
-
parseAndSetInt
protected java.lang.String parseAndSetInt(Ice.InitializationData data, java.lang.String key, int newValue)
-
filesToString
protected static java.lang.String filesToString(java.io.File... files)
-
env
protected ISessionPrx env() throws ServerError
Helper method to access session environment- Throws:
ServerError
-
onHeartbeat
public void onHeartbeat(java.lang.Runnable runnable)
-
onSessionClosed
public void onSessionClosed(java.lang.Runnable runnable)
-
onShutdown
public void onShutdown(java.lang.Runnable runnable)
-
-