X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FSimpleClient.java;h=6e40df0b5f4d8ecccab73392347855fd49b8636c;hb=844ccad5a3fcbedec17b2af66d460f31abc7cff1;hp=8e8fba22ac318847d6c9758c3bb5ddef68a8758e;hpb=b4dc48a6b8be7fa6628bc61599b4678030c4084e;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java index 8e8fba2..6e40df0 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java @@ -1,8 +1,23 @@ /* - * Created on 15-Sep-2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates + * This file is part of the Vamsas Client version 0.1. + * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, + * Andrew Waterhouse and Dominik Lindner. + * + * Earlier versions have also been incorporated into Jalview version 2.4 + * since 2008, and TOPALi version 2 since 2007. + * + * The Vamsas Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Vamsas Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Vamsas Client. If not, see . */ package uk.ac.vamsas.client.simpleclient; @@ -25,6 +40,7 @@ import uk.ac.vamsas.client.Events; import uk.ac.vamsas.client.IClient; import uk.ac.vamsas.client.IClientDocument; import uk.ac.vamsas.client.IObjectUpdate; +import uk.ac.vamsas.client.InvalidSessionDocumentException; import uk.ac.vamsas.client.InvalidSessionUrnException; import uk.ac.vamsas.client.SessionHandle; import uk.ac.vamsas.client.UserHandle; @@ -37,98 +53,104 @@ import uk.ac.vamsas.objects.utils.ProvenanceStuff; * @author jimp */ public class SimpleClient implements IClient { - + private static Log log = LogFactory.getLog(SimpleClient.class); - + protected UserHandle user = null; - + protected SessionUrn session = null; + protected VamsasSession _session; + protected ClientHandle client = null; + protected EventGeneratorThread evgen = null; + protected ClientDocument cdocument = null; - - - - + private Lock activeClientFilelock = null; - private File clientlockFile = null; - + + private File clientlockFile = null; + /** - * object hash table that persists in each client holding vorbaIds and hash values after a document write + * object hash table that persists in each client holding vorbaIds and hash + * values after a document write */ - protected Hashtable extantobjects=null; + protected Hashtable extantobjects = null; + /** - * construct a transient IdFactory instance - this should last only as long as the - * SimpleClient object holds the lock on the vamsas document being created/manipulated. + * construct a transient IdFactory instance - this should last only as long as + * the SimpleClient object holds the lock on the vamsas document being + * created/manipulated. + * * @return */ private IdFactory makeVorbaIdFactory() { - if (extantobjects==null) - extantobjects=new Hashtable(); + if (extantobjects == null) + extantobjects = new Hashtable(); return new IdFactory(getSessionHandle(), client, user, extantobjects); } - + /** - * construct SimpleClient for user, client and VamsasSession directory - * use the SimpleClientFactory rather than this constructor directly. + * construct SimpleClient for user, client and VamsasSession directory use the + * SimpleClientFactory rather than this constructor directly. + * * @param user * @param client * @param sess */ - protected SimpleClient(UserHandle user, ClientHandle client, VamsasSession sess) throws InvalidSessionUrnException { + protected SimpleClient(UserHandle user, ClientHandle client, + VamsasSession sess) throws InvalidSessionUrnException { // TODO: validate user/client/session _session = sess; this.user = user; this.client = client; - //try { - log.debug("Creating new session for "+_session); - session = new SessionUrn(_session); - log.debug("Creating new Event Generator"); - evgen = new EventGeneratorThread(_session, this, handlers); - /*} catch (MalformedURLException e) { - log.error("Couldn't form a valid SessionUrn object!",e); - throw new InvalidSessionUrnException(_session.toString()); - }*/ - log.debug("SimpleClient constructed for session "+session.getSessionUrn()); - + // try { + log.debug("Creating new session for " + _session); + session = new SessionUrn(_session); + log.debug("Creating new Event Generator"); + evgen = new EventGeneratorThread(_session, this, handlers); + /* + * } catch (MalformedURLException e) { + * log.error("Couldn't form a valid SessionUrn object!",e); throw new + * InvalidSessionUrnException(_session.toString()); } + */ + log + .debug("SimpleClient constructed for session " + + session.getSessionUrn()); + } + /** - * construct new session by importing objects from an existing vamsas document + * construct new SimpleClientsession by importing objects from an existing + * vamsas document + * * @param user * @param client * @param sess * @param importingArchive - * @throws Exception IOExceptions for Session IO problems, and general Exception if importing document is invalid. + * @throws Exception + * IOExceptions for Session IO problems, and general Exception if + * importing document is invalid. protected SimpleClient(UserHandle + * user, ClientHandle client, VamsasSession sess, File + * importingArchive) throws Exception { this(user, client, sess); if + * (log.isDebugEnabled()) { + * log.debug("Attempting to overwrite session document with file: " + * +importingArchive); } // TODO: write provenance entry for new + * session indicating the import. + * + * } */ - protected SimpleClient(UserHandle user, ClientHandle client, VamsasSession sess, File importingArchive) throws Exception { - this(user, client, sess); - VamsasArchive sessdoc = _session.getVamsasDocument(); - try { - VamsasArchiveReader odoc = new VamsasArchiveReader(importingArchive); - SimpleDocument sdoc = new SimpleDocument(makeVorbaIdFactory()); - VamsasDocument doc = sdoc.getVamsasDocument(odoc); - sessdoc.putVamsasDocument(doc, sdoc.vorba); - sessdoc.closeArchive(); - log.debug("Imported new vamsas data from "+importingArchive); - } catch (Exception e) { - sessdoc.cancelArchive(); - // write a dummy iohandler - _session.slog.info("Exception when importing document data from "+importingArchive); - log.warn("While importing session data from existing archive in "+importingArchive, e); - throw new Exception("Failed to import data from "+importingArchive, e); - } - } - + /* - * (non-Javadoc) - * LATER: check that build substitution variables are correct + * (non-Javadoc) LATER: check that build substitution variables are correct + * * @see uk.ac.vamsas.client.IClient#getAbout() */ public String getAbout() { return new String("VORBA SimpleClient version $version$ build $build$"); } - + /* * (non-Javadoc) * @@ -137,7 +159,7 @@ public class SimpleClient implements IClient { public String getSessionUrn() { return session.getSessionUrn(); } - + /* * (non-Javadoc) * @@ -148,7 +170,7 @@ public class SimpleClient implements IClient { SessionHandle sh = new SessionHandle(session.getSessionUrn()); return sh; } - + /* * (non-Javadoc) * @@ -157,7 +179,7 @@ public class SimpleClient implements IClient { public ClientHandle getClientHandle() { return client; } - + /* * (non-Javadoc) * @@ -166,6 +188,7 @@ public class SimpleClient implements IClient { public UserHandle getUserHandle() { return user; } + /** * * @return user field for a provenance entry @@ -173,22 +196,28 @@ public class SimpleClient implements IClient { protected String getProvenanceUser() { return new String(user.getFullName()); } + /** - * construct a provenance entry for this client with the specified action string. + * construct a provenance entry for this client with the specified action + * string. + * * @param action * @return properly completed provenance entry */ protected Entry getProvenanceEntry(String action) { - Entry prov = ProvenanceStuff.newProvenanceEntry(client.getClientUrn(), getProvenanceUser(), action); + Entry prov = ProvenanceStuff.newProvenanceEntry(client.getClientUrn(), + getProvenanceUser(), action); return prov; } + private Hashtable handlers = initHandlers(); - + private Vector listeners = new Vector(); - + /** - * make all the PropertyChangeSupport objects for the - * events described in uk.ac.vamsas.client.Event + * make all the PropertyChangeSupport objects for the events described in + * uk.ac.vamsas.client.Event + * * @return */ private static Hashtable initHandlers() { @@ -200,19 +229,23 @@ public class SimpleClient implements IClient { } return events; } - + /* * (non-Javadoc) * - * @see uk.ac.vamsas.client.IClient#addDocumentUpdateHandler(java.util.EventListener) + * @see + * uk.ac.vamsas.client.IClient#addDocumentUpdateHandler(java.util.EventListener + * ) */ public void addDocumentUpdateHandler(PropertyChangeListener evt) { this.addVorbaEventHandler(Events.DOCUMENT_UPDATE, evt); } - boolean finalized=false; + + boolean finalized = false; + private void haltPickmanager() { - if (pickmanager!=null) { - final SimpleClient dying=this; + if (pickmanager != null) { + final SimpleClient dying = this; new Thread() { public void run() { SimpleClient.log.debug("Stopping pickManager.."); @@ -222,6 +255,7 @@ public class SimpleClient implements IClient { }.start(); } } + /* * (non-Javadoc) * @@ -229,30 +263,32 @@ public class SimpleClient implements IClient { */ public void finalizeClient() { if (finalized) - throw new Error("VAMSAS Client Implementation Error: Finalized called twice for same client instance."); + throw new Error( + "VAMSAS Client Implementation Error: Finalized called twice for same client instance."); // mark this instance as finalized - finalized=true; - + finalized = true; + // TODO: determine if this is last client in session - - // TODO: raise events like : ((lst_client && document.request.to.close), (client_finalization), ( - evgen._raise(Events.CLIENT_FINALIZATION, null, this,null); + + // TODO: raise events like : ((lst_client && document.request.to.close), + // (client_finalization), ( + evgen._raise(Events.CLIENT_FINALIZATION, null, this, null); // if (handlers.containsKey(Events.)) // if (handlers.containsKey(Events.CLIENT_FINALIZATION)) // deregister listeners. log.debug("Stopping pickManager"); haltPickmanager(); - + log.debug("Deregistering Client"); _session.removeClient(this); - //log.debug("Stopping EventGenerator.."); - //evgen.stopWatching(); - SimpleClient.log.debug("EventGenerator halted."); + // log.debug("Stopping EventGenerator.."); + // evgen.stopWatching(); this.cdocument = null; + SimpleClient.log.debug("EventGenerator halted."); log.debug("finalization Complete."); } - + /* * (non-Javadoc) * @@ -260,8 +296,9 @@ public class SimpleClient implements IClient { */ public IClientDocument getClientDocument() throws IOException { log.debug("getClientDocument"); - if (cdocument!=null) { - // cdocument is non-nill if the ClientDocument.finalise() method hasn't been called. + if (cdocument != null) { + // cdocument is non-nill if the ClientDocument.finalise() method hasn't + // been called. return cdocument; } evgen.disableDocumentWatch(); @@ -269,63 +306,83 @@ public class SimpleClient implements IClient { try { // LATER: bail out if it takes too long to get the lock ? va = _session.getVamsasDocument(); - } - catch (IOException e) { + } catch (IOException e) { throw new IOException("Failed to get lock on session document"); } - VamsasDocument doc=null; + VamsasDocument doc = null; IdFactory vorba = null; - // TODO: LATER: reduce size of vorba ids generated from these parameters to IdFactory (mainly sessionHandle rationalization ?) + // TODO: LATER: reduce size of vorba ids generated from these parameters to + // IdFactory (mainly sessionHandle rationalization ?) try { - va.setVorba(vorba=makeVorbaIdFactory()); + va.setVorba(vorba = makeVorbaIdFactory()); // if session currently holds data - read it in - or get a dummy log.debug("Accessing document"); - doc = - va.getVamsasDocument(getProvenanceUser(), - "created new session document.", null); - if (doc!=null) + doc = va.getVamsasDocument(getProvenanceUser(), + "created new session document.", null); + if (doc != null) log.debug("Successfully retrieved document."); else log.error("Unexpectedly retrieved null document!"); - } - catch (Exception e) { - log.error("Failed to get session document for session directory '"+_session.sessionDir+"'", e); - throw new IOException("Failed to get session document for session directory '"+_session.sessionDir+"'"); + } catch (Exception e) { + log.error("Failed to get session document for session directory '" + + _session.sessionDir + "'", e); + throw new IOException( + "Failed to get session document for session directory '" + + _session.sessionDir + "'"); } // Construct the IClientDocument instance - + cdocument = new ClientDocument(doc, va, vorba, this); return cdocument; } - + /* * (non-Javadoc) + * * @throws Errors for invalid newdoc parameter - * @see uk.ac.vamsas.client.IClient#updateDocument(uk.ac.vamsas.client.IClientDocument) + * + * @see + * uk.ac.vamsas.client.IClient#updateDocument(uk.ac.vamsas.client.IClientDocument + * ) */ public void updateDocument(IClientDocument newdoc) { log.debug("updateDocument:"); - // Check validity of simpleclient instance and that it holds a lock on the session's document + // Check validity of simpleclient instance and that it holds a lock on the + // session's document if (!(newdoc instanceof ClientDocument)) { throw new Error("Invalid IClientDocument passsed to SimpleClient."); } - if (cdocument==null) - throw new Error("Client Error - updateDocument() called before getClientDocument() on this SimpleClient instance."); - if (newdoc!=cdocument) - throw new Error("Client Error - SimpleClient.updateDocument() can only take the IClientDocument instance returned from SimpleClient.getClientDocument()"); - + if (cdocument == null) + throw new Error( + "Client Error - updateDocument() called before getClientDocument() on this SimpleClient instance."); + if (newdoc != cdocument) + throw new Error( + "Client Error - SimpleClient.updateDocument() can only take the IClientDocument instance returned from SimpleClient.getClientDocument()"); + if (evgen.isDocumentWatchEnabled()) - throw new Error("Probable Client Error (did you remember to call SimpleClient.updateDocument(clientdoc) at the end of the document update handler?) - or Library Bug : Document watcher still enabled whilst ClientDocument instance exists."); - - if (!cdocument.isModified()) { - // client document is silently got rid of, with no session update events. - if (log.isDebugEnabled()) - log.debug("updateDocument for "+session.getSessionUrn()+" with unmodified IClientDocument (skipping the write)"); + throw new Error( + "Probable Client Error (did you remember to call SimpleClient.updateDocument(clientdoc) at the end of the document update handler?) - or Library Bug : Document watcher still enabled whilst ClientDocument instance exists."); + if (cdocument.isInvalidModification()) { + log + .info("Client has corrupted the vamsas document. It will not be written back to the session - sorry."); + // TODO: modify updateDocument signature: We should really raise an + // exception here to tell the client that it broke the datamodel. } else { - writeSessionDocument(); + // actually try to write - if necessary. + if (!cdocument.isModified()) { + // client document is silently got rid of, with no session update + // events. + if (log.isDebugEnabled()) + log.debug("updateDocument for " + session.getSessionUrn() + + " with unmodified IClientDocument (skipping the write)"); + } else { + writeSessionDocument(); + } } - tidyAwaySessionDocumentState(); + // release locks, reset and start to receive events again + tidyAwaySessionDocumentState(); } + /** * garbage collect the ClientDocument instance and re-enable watchers. */ @@ -334,7 +391,8 @@ public class SimpleClient implements IClient { log.debug("Finalizing ClientDocument instance."); cdocument.finalize(); } catch (Throwable e) { - log.error("Exception when trying to garbage collect ClientDocument for "+session.getSessionUrn(), e); + log.error("Exception when trying to garbage collect ClientDocument for " + + session.getSessionUrn(), e); } cdocument = null; // this is probably done by finalize @@ -342,8 +400,9 @@ public class SimpleClient implements IClient { _session.unlockVamsasDocument(); evgen.enableDocumentWatch(); } catch (IOException e) { - log.warn("IO Problems when releasing lock on session document!",e); - _session.slog.error("IO problems when attempting to release lock on session document."); + log.warn("IO Problems when releasing lock on session document!", e); + _session.slog + .error("IO problems when attempting to release lock on session document."); } } @@ -352,18 +411,24 @@ public class SimpleClient implements IClient { */ private void writeSessionDocument() { try { - boolean updated=cdocument.updateSessionDocument(); + boolean updated = cdocument.updateSessionDocument(); + boolean hasContent = cdocument.isModified(); if (!updated) { - log.warn("Session document did not update properly for session directory "+_session.sessionDir); - // cdocument.archive.cancelArchive(); // LATER: could be done - would need to prevent updateSessionDocument closing the iohandler. - _session.slog.warn("Session Document updated but may not be valid (false return from org.vamsas.simpleclient.ClientDocument.updateSessionDocument()"); + log + .warn("Session document did not update properly for session directory " + + _session.sessionDir); + // cdocument.archive.cancelArchive(); // LATER: could be done - would + // need to prevent updateSessionDocument closing the iohandler. + _session.slog + .warn("Session Document updated but may not be valid (false return from org.vamsas.simpleclient.ClientDocument.updateSessionDocument()"); } else { log.debug("Document update successful."); } - _session.setUnsavedFlag(); - } - catch (IOException e) { - log.warn("IO Problems when updating document!",e); + if (hasContent) { + _session.setUnsavedFlag(); + } + } catch (IOException e) { + log.warn("IO Problems when updating document!", e); _session.slog.error("IO problems when attempting to update document."); } } @@ -374,105 +439,115 @@ public class SimpleClient implements IClient { * @see uk.ac.vamsas.client.IClient#storeDocument(java.io.File) */ public void storeDocument(File location) { - if (location==null) - throw new Error("Vamsas Client API Usage Error: storeDocument called with null location."); - log.debug("StoreDocument to "+location); + if (location == null) + throw new Error( + "Vamsas Client API Usage Error: storeDocument called with null location."); + log.debug("StoreDocument to " + location); // write storeDocument file to inform other clients that they should raise Lock vamlock = evgen.want_to_store(); // Events.DOCUMENT_FINALIZEAPPDATA try { _session.writeVamsasDocument(location, vamlock); - _session.clearUnsavedFlag(); + _session.clearUnsavedFlag(); } catch (Exception e) { - log.warn("Exception whilst trying to store document in "+location,e); + log.warn("Exception whilst trying to store document in " + location, e); } vamlock.release(); } - + /* * (non-Javadoc) * * @see uk.ac.vamsas.client.IClient#addVorbaEventHandler(java.lang.String, - * java.beans.PropertyChangeListener) + * java.beans.PropertyChangeListener) */ public void addVorbaEventHandler(String EventChain, PropertyChangeListener evt) { if (handlers.containsKey(EventChain)) { - log.debug("Adding new handler for "+EventChain); + log.debug("Adding new handler for " + EventChain); Object handler; ((PropertyChangeSupport) (handler = handlers.get(EventChain))) - .addPropertyChangeListener(evt); + .addPropertyChangeListener(evt); listeners.add(handler); listeners.add((Object) evt); } } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see uk.ac.vamsas.client.IClient#pollUpdate() */ public void pollUpdate() { log.debug("pollUpdate"); - if (evgen==null) { + if (evgen == null) { log.warn("pollUpdate called on incomplete SimpleClient object."); return; } - + if (!evgen.isWatcherAlive()) { log.warn("pollUpdate called before joinSession() - trying to do this."); try { joinSession(); } catch (Exception e) { - log.error("Unexpected exception on default call to joinSession",e); + log.error("Unexpected exception on default call to joinSession", e); } } - - //TODO ensure event generator robustly handles these interrupts. + + // TODO ensure event generator robustly handles these interrupts. log.debug("interrrupting event generator."); evgen.interruptWatching(); log.debug("interrrupted event generator."); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see uk.ac.vamsas.client.IClient#joinSession() */ public void joinSession() throws Exception { log.debug("Joining Session."); // start the EventGenerator thread. - if (evgen==null) { + if (evgen == null) { log.warn("joinSession called on incomplete SimpleClient object."); return; } if (evgen.isWatcherAlive()) - throw new Error("Join session called twice for the same SimpleClient (IClient instance)."); + throw new Error( + "Join session called twice for the same SimpleClient (IClient instance)."); evgen.startWatching(); if (evgen.isWatcherAlive()) log.debug("Started EventGenerator thread."); else { log.warn("Failed to start EventGenerator thread."); - throw new Exception("Failed to start event generator thread - client cannot be instantiated."); + throw new Exception( + "Failed to start event generator thread - client cannot be instantiated."); } - if (evgen.countHandlersFor(Events.DOCUMENT_CREATE)>0) { - //TODO: LATER: is this application connecting to a newly created session document ? - //evgen.raise(Events.DOCUMENT_CREATE); + if (evgen.countHandlersFor(Events.DOCUMENT_CREATE) > 0) { + // TODO: LATER: is this application connecting to a newly created session + // document ? + // evgen.raise(Events.DOCUMENT_CREATE); } - + } - - - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see uk.ac.vamsas.client.IClient#importDocument(java.io.File) */ public void importDocument(File location) { // TODO LATER: implement SimpleClient.importDocument() - // if (numberOfClients<1 or document file is empty/new, then can import directly.) - // more complex if data is already present in document. Could have a 'clearSession' method, too, or dump and overwrite instead. - log.error("importDocument is not yet implemented for a SimpleClient Session."); - - /*try { - this._session.setVamsasDocument(location); - } catch (IOException e) { - log.error("importDocument failed."); - }*/ + // if (numberOfClients<1 or document file is empty/new, then can import + // directly.) + // more complex if data is already present in document. Could have a + // 'clearSession' method, too, or dump and overwrite instead. + log + .error("importDocument is not yet implemented for a SimpleClient Session."); + + /* + * try { this._session.setVamsasDocument(location); } catch (IOException e) + * { log.error("importDocument failed."); } + */ } public IObjectUpdate getUpdateHandler(Class rootObject) { @@ -487,23 +562,28 @@ public class SimpleClient implements IClient { public void removeUpdateHandler(Class rootObject) { // TODO Auto-generated method stub - + } public void setUpdateHandler(IObjectUpdate handler) { // TODO Auto-generated method stub - + } /** * retrieves the current VamsasSession to which belong the client + * * @return the _session */ protected VamsasSession get_session() { return this._session; } - SimplePickManager pickmanager=null; - /* (non-Javadoc) + + SimplePickManager pickmanager = null; + + /* + * (non-Javadoc) + * * @see uk.ac.vamsas.client.IClient#getPickManager() */ public IPickManager getPickManager() { @@ -512,76 +592,81 @@ public class SimpleClient implements IClient { } private void createPickManager() { - if (pickmanager==null){ + if (pickmanager == null) { // TODO: Construct PickManager for session using details from sessionURN! log.debug("Creating PickManager (not from sessionURN yet)"); - pickmanager = new SimplePickManager(new uk.ac.vamsas.client.picking.SocketManager()); + pickmanager = new SimplePickManager( + new uk.ac.vamsas.client.picking.SocketManager()); } } - - - protected void releaseActiveClientFile() throws IOException - { - + + protected void releaseActiveClientFile() throws IOException { + log.debug("Releasing active client locks"); - if( activeClientFilelock != null) - {// Release the lock + if (activeClientFilelock != null) {// Release the lock log.debug("Releasing lock on active client lock file"); activeClientFilelock.release(); - log.debug("ReleaseActiveClientFile called when client has no lock on its clientLockFile"); + log + .debug("ReleaseActiveClientFile called when client has no lock on its clientLockFile"); activeClientFilelock = null; } else { - log.debug("ReleaseActiveClientFile called when client has no lock on its clientLockFile"); + log + .debug("ReleaseActiveClientFile called when client has no lock on its clientLockFile"); } - if (this.clientlockFile != null) - { + if (this.clientlockFile != null) { log.debug("trying to delete active client lock file"); - if (this.clientlockFile.exists()) - { + if (this.clientlockFile.exists()) { this.clientlockFile.delete(); log.debug("deleted active client lock file"); } } else { - log.debug("ReleaseActiveClientFile called when client has no clientLockFile"); + log + .debug("ReleaseActiveClientFile called when client has no clientLockFile"); } } - - protected void createActiveClientFile() throws IOException - { - if(this.clientlockFile != null )return; - log.debug("createActiveClientFile"); - //create, if need, subdirectory to contain client files - File clientlockFileDir = new File ( this.get_session().sessionDir, this.get_session().clientFileDirectory); - if( !clientlockFileDir.exists()) - {//the directory does not exist, create it - if (! clientlockFileDir.mkdirs()) - { - throw new IOException("Failed to create sub directory to session directory for client lock files'"+clientlockFileDir.getAbsolutePath()+"'"); - } + + protected void createActiveClientFile() throws IOException { + if (this.clientlockFile != null) + return; + log.debug("createActiveClientFile"); + // create, if need, subdirectory to contain client files + File clientlockFileDir = new File(this.get_session().sessionDir, this + .get_session().clientFileDirectory); + if (!clientlockFileDir.exists()) {// the directory does not exist, create it + if (!clientlockFileDir.mkdirs()) { + throw new IOException( + "Failed to create sub directory to session directory for client lock files'" + + clientlockFileDir.getAbsolutePath() + "'"); + } + } else { + if (!(clientlockFileDir.isDirectory() && clientlockFileDir.canWrite())) { + throw new IOException( + "Directory for client lock files is not a directory or is not accessibl: '" + + clientlockFileDir.getAbsolutePath() + "'"); } - else - { - if (!(clientlockFileDir.isDirectory() && clientlockFileDir.canWrite())) - { - throw new IOException("Directory for client lock files is not a directory or is not accessibl: '"+clientlockFileDir.getAbsolutePath()+"'"); - } } - this.clientlockFile = new File (clientlockFileDir, this.getClientHandle().getClientUrn().replaceAll("[:;/\\\\]+","")); - - log.debug("Creating active client lock file "+ this.clientlockFile.getAbsolutePath()); - Lock clientLock = uk.ac.vamsas.client.simpleclient.LockFactory.getLock(clientlockFile, false); - if (clientLock==null || !clientLock.isLocked()) - { - log.fatal("IMPLEMENTATION ERROR: Couldn't get a lock for the client lock file "+clientlockFile); + this.clientlockFile = new File(clientlockFileDir, this.getClientHandle() + .getClientUrn().replaceAll("[:;/\\\\]+", "")); + + log.debug("Creating active client lock file " + + this.clientlockFile.getAbsolutePath()); + Lock clientLock = uk.ac.vamsas.client.simpleclient.LockFactory.getLock( + clientlockFile, false); + if (clientLock == null || !clientLock.isLocked()) { + log + .fatal("IMPLEMENTATION ERROR: Couldn't get a lock for the client lock file " + + clientlockFile); } activeClientFilelock = clientLock; } + /** * @return the clientlockFile */ protected File getClientlockFile() { return clientlockFile; } + /** * * @return the lock for the client in the session @@ -590,4 +675,13 @@ public class SimpleClient implements IClient { return activeClientFilelock; } + SimpleClientConfig _config = null; + + public SimpleClientConfig getSimpleClientConfig() { + if (_config == null) { + _config = new SimpleClientConfig(); + } + return _config; + } + }