Author: glandais Date: 2008-02-13 08:57:08 +0000 (Wed, 13 Feb 2008) New Revision: 896 Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/SimExplorerServiceStream.java Log: Magic stream clean up with transient trick for detecting remote mode Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/SimExplorerServiceStream.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/SimExplorerServiceStream.java 2008-02-13 02:51:00 UTC (rev 895) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/SimExplorerServiceStream.java 2008-02-13 08:57:08 UTC (rev 896) @@ -32,14 +32,13 @@ * * Simplify usage of remote streams. * - * To allow magic remoting, your - * stream has to encapsulated in a SimExplorerServiceStream with + * To allow magic remoting, your stream has to encapsulated in a SimExplorerServiceStream with * - * <code> + * <code> * SimExplorerServiceStream serviceStream = new SimExplorerServiceStream(myStream); * service.method(serviceStream); * </code> - * + * * Stream will work, even through a RMI call. * */ @@ -54,6 +53,8 @@ /** The local stream, set to null if stream is serialized. */ transient private BufferedInputStream bis; + private boolean initialized; + /** * Instantiates a new stream. * @@ -64,11 +65,13 @@ // Set local stream (null if this is serialized) this.bis = new BufferedInputStream(bis); try { - // Create a stub if possible, used in init - this.ris = new SimpleRemoteInputStream(bis).export(); + // Create a stub, used in init + ris = new SimpleRemoteInputStream(bis).export(); } catch (RemoteException e) { - this.ris = null; + ris = null; } + + initialized = false; } /** @@ -77,16 +80,22 @@ * Called before every delegated method */ private void init() { - // Check is local stream is ok - if (bis == null) { - try { - // Otherwise use RMIIO to retrieve remote stream - this.bis = new BufferedInputStream(RemoteInputStreamClient - .wrap(ris)); - } catch (IOException e) { - // Something went wrong during transformation - throw new RuntimeException(e); + if (!initialized) { + // Check is local stream is null (ie as been serialized) + if (bis != null) { + // remote stream is useless in that case + ris = null; + } else { + try { + // Otherwise use RMIIO to retrieve remote stream + bis = new BufferedInputStream(RemoteInputStreamClient + .wrap(ris)); + } catch (IOException e) { + // Something went wrong during transformation + throw new RuntimeException(e); + } } + initialized = true; } }
participants (1)
-
glandais@users.labs.libre-entreprise.org