Return-Path: X-Original-To: apmail-river-commits-archive@www.apache.org Delivered-To: apmail-river-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 65B1E10AED for ; Mon, 15 Apr 2013 15:27:28 +0000 (UTC) Received: (qmail 34739 invoked by uid 500); 15 Apr 2013 15:27:27 -0000 Delivered-To: apmail-river-commits-archive@river.apache.org Received: (qmail 34659 invoked by uid 500); 15 Apr 2013 15:27:27 -0000 Mailing-List: contact commits-help@river.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@river.apache.org Delivered-To: mailing list commits@river.apache.org Received: (qmail 34622 invoked by uid 99); 15 Apr 2013 15:27:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Apr 2013 15:27:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Apr 2013 15:27:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 465B72388B34; Mon, 15 Apr 2013 15:26:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1468119 [5/15] - in /river/jtsk/skunk/qa_refactor/trunk: qa/src/com/sun/jini/qa/harness/ qa/src/com/sun/jini/test/impl/mahalo/ qa/src/com/sun/jini/test/resources/ qa/src/com/sun/jini/test/share/ qa/src/com/sun/jini/test/spec/javaspace/conf... Date: Mon, 15 Apr 2013 15:26:46 -0000 To: commits@river.apache.org From: peter_firmstone@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130415152659.465B72388B34@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/StorableObject.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/StorableObject.java?rev=1468119&r1=1468118&r2=1468119&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/StorableObject.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/StorableObject.java Mon Apr 15 15:26:44 2013 @@ -1,117 +1,133 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.sun.jini.mahalo; - -import java.io.IOException; -import java.rmi.MarshalledObject; -import java.rmi.RemoteException; - - -/** - * This class holds a MarshalledObject that can be stored - * persistently. When you invoke get, the object is - * deserialized, its value cached in this object, and then returned. - * Subsequent calls to get return that value. This lets - * you store the object and hold it around, waiting until it is - * actually deserializable, since it may not be at any given time due - * to various factors, such as the codebase being unavailable. - * - * @author Sun Microsystems, Inc. - * - */ -public class StorableObject implements java.io.Serializable { - /** - * @serial - */ - private MarshalledObject bytes; // the serialized bytes - private transient Object obj; // the cached object reference - - private static final boolean DEBUG = false; - private static final long serialVersionUID = -3793675220968988873L; - - /** - * Create a StorableObject that will hold obj - * in a MarshalledObject. - */ - public StorableObject(Object obj) throws RemoteException { - try { - bytes = new MarshalledObject(obj); - this.obj = obj; - } catch (RemoteException e) { - throw e; - } catch (IOException e) { - fatalError("can't encode object", e); - } - } - - /** - * Return the hashCode of the MarshalledObject. - */ - public int hashCode() { - return bytes.hashCode(); // value of obj.hashCode() - } - - public boolean equals(Object that) { - try { - if (that instanceof StorableObject) - return get().equals(((StorableObject) that).get()); - else - return get().equals(that); - } catch (RemoteException e) { - return false; //!! or should I just die? - } - } - - /** - * Return the Remote reference. Deserialize the object if we don't - * already have an actual reference in hand. - * - * @exception java.rmi.RemoteException - * Problems re-establishing connection with remote object - */ - public Object get() throws RemoteException { - try { - if (obj == null) - obj = bytes.get(); - return obj; - } catch (RemoteException e) { - if (DEBUG) - System.out.println("*****StorableObject:get:" + e.getMessage()); - throw e; - } catch (IOException e) { - fatalError("can't decode object", e); - } catch (ClassNotFoundException e) { - fatalError("can't decode object", e); - } - fatalError("how did we get here?", null); - return null; // not reached, but compiler doesn't know - } - - /** - * Unrecoverable error happened -- show it and give up the ghost. - */ - private static void fatalError(String msg, Throwable e) - throws RemoteException - { - System.err.println(msg); - if (e != null) - e.printStackTrace(System.err); - throw new RemoteException(msg, e); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.sun.jini.mahalo; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.rmi.MarshalledObject; +import java.rmi.RemoteException; + + +/** + * This class holds a MarshalledObject that can be stored + * persistently. When you invoke get, the object is + * deserialized, its value cached in this object, and then returned. + * Subsequent calls to get return that value. This lets + * you store the object and hold it around, waiting until it is + * actually deserializable, since it may not be at any given time due + * to various factors, such as the codebase being unavailable. + * + * @author Sun Microsystems, Inc. + * + */ +public class StorableObject implements java.io.Serializable { + /** + * @serial + */ + private final MarshalledObject bytes; // the serialized bytes + private volatile transient Object obj; // the cached object reference + + private static final boolean DEBUG = false; + private static final long serialVersionUID = -3793675220968988873L; + + /** + * Create a StorableObject that will hold obj + * in a MarshalledObject. + */ + public StorableObject(Object obj) throws RemoteException { + this(obj, toMO(obj)); + } + + private static MarshalledObject toMO(Object obj) throws RemoteException{ + try { + return new MarshalledObject(obj); + } catch (RemoteException e){ + throw e; + } catch (IOException e){ + fatalError("can't encode object", e); + } + return null; //Unreachable. + } + + private StorableObject (Object obj, MarshalledObject mo){ + bytes = mo; + this.obj = obj; + } + + /** + * Return the hashCode of the MarshalledObject. + */ + public int hashCode() { + return bytes.hashCode(); // value of obj.hashCode() + } + + public boolean equals(Object that) { + try { + if (that instanceof StorableObject) + return get().equals(((StorableObject) that).get()); + else + return get().equals(that); + } catch (RemoteException e) { + return false; //!! or should I just die? + } + } + + /** + * Return the Remote reference. Deserialize the object if we don't + * already have an actual reference in hand. + * + * @exception java.rmi.RemoteException + * Problems re-establishing connection with remote object + */ + public Object get() throws RemoteException { + try { + if (obj == null) + obj = bytes.get(); + return obj; + } catch (RemoteException e) { + if (DEBUG) + System.out.println("*****StorableObject:get:" + e.getMessage()); + throw e; + } catch (IOException e) { + fatalError("can't decode object", e); + } catch (ClassNotFoundException e) { + fatalError("can't decode object", e); + } + fatalError("how did we get here?", null); + return null; // not reached, but compiler doesn't know + } + + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException + { + s.defaultReadObject(); // Just in case we change serial form later. + } + + /** + * Unrecoverable error happened -- show it and give up the ghost. + */ + private static void fatalError(String msg, Throwable e) + throws RemoteException + { + System.err.println(msg); + if (e != null) + e.printStackTrace(System.err); + throw new RemoteException(msg, e); + } +}