Showing the changes to java/pkg/java/rmi/dgc (9 of 18352 files). Show all
Unified · Split
Binary file not shown.
| @@ -0,0 +1,115 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | package java.rmi.dgc; | ||
| 26 | |||
| 27 | import java.rmi.*; | ||
| 28 | import java.rmi.server.ObjID; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * The DGC abstraction is used for the server side of the distributed | ||
| 32 | * garbage collection algorithm. This interface contains the two | ||
| 33 | * methods: dirty and clean. A dirty call is made when a remote | ||
| 34 | * reference is unmarshaled in a client (the client is indicated by | ||
| 35 | * its VMID). A corresponding clean call is made when no more | ||
| 36 | * references to the remote reference exist in the client. A failed | ||
| 37 | * dirty call must schedule a strong clean call so that the call's | ||
| 38 | * sequence number can be retained in order to detect future calls | ||
| 39 | * received out of order by the distributed garbage collector. | ||
| 40 | * | ||
| 41 | * A reference to a remote object is leased for a period of time by | ||
| 42 | * the client holding the reference. The lease period starts when the | ||
| 43 | * dirty call is received. It is the client's responsibility to renew | ||
| 44 | * the leases, by making additional dirty calls, on the remote | ||
| 45 | * references it holds before such leases expire. If the client does | ||
| 46 | * not renew the lease before it expires, the distributed garbage | ||
| 47 | * collector assumes that the remote object is no longer referenced by | ||
| 48 | * that client. | ||
| 49 | * | ||
| 50 | * @author Ann Wollrath | ||
| 51 | */ | ||
| 52 | public interface DGC extends Remote { | ||
| 53 | |||
| 54 | /** | ||
| 55 | * The dirty call requests leases for the remote object references | ||
| 56 | * associated with the object identifiers contained in the array | ||
| 57 | * 'ids'. The 'lease' contains a client's unique VM identifier (VMID) | ||
| 58 | * and a requested lease period. For each remote object exported | ||
| 59 | * in the local VM, the garbage collector maintains a reference | ||
| 60 | * list-a list of clients that hold references to it. If the lease | ||
| 61 | * is granted, the garbage collector adds the client's VMID to the | ||
| 62 | * reference list for each remote object indicated in 'ids'. The | ||
| 63 | * 'sequenceNum' parameter is a sequence number that is used to | ||
| 64 | * detect and discard late calls to the garbage collector. The | ||
| 65 | * sequence number should always increase for each subsequent call | ||
| 66 | * to the garbage collector. | ||
| 67 | * | ||
| 68 | * Some clients are unable to generate a VMID, since a VMID is a | ||
| 69 | * universally unique identifier that contains a host address | ||
| 70 | * which some clients are unable to obtain due to security | ||
| 71 | * restrictions. In this case, a client can use a VMID of null, | ||
| 72 | * and the distributed garbage collector will assign a VMID for | ||
| 73 | * the client. | ||
| 74 | * | ||
| 75 | * The dirty call returns a Lease object that contains the VMID | ||
| 76 | * used and the lease period granted for the remote references (a | ||
| 77 | * server may decide to grant a smaller lease period than the | ||
| 78 | * client requests). A client must use the VMID the garbage | ||
| 79 | * collector uses in order to make corresponding clean calls when | ||
| 80 | * the client drops remote object references. | ||
| 81 | * | ||
| 82 | * A client VM need only make one initial dirty call for each | ||
| 83 | * remote reference referenced in the VM (even if it has multiple | ||
| 84 | * references to the same remote object). The client must also | ||
| 85 | * make a dirty call to renew leases on remote references before | ||
| 86 | * such leases expire. When the client no longer has any | ||
| 87 | * references to a specific remote object, it must schedule a | ||
| 88 | * clean call for the object ID associated with the reference. | ||
| 89 | * | ||
| 90 | * @param ids IDs of objects to mark as referenced by calling client | ||
| 91 | * @param sequenceNum sequence number | ||
| 92 | * @param lease requested lease | ||
| 93 | * @return granted lease | ||
| 94 | * @throws RemoteException if dirty call fails | ||
| 95 | */ | ||
| 96 | Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) | ||
| 97 | throws RemoteException; | ||
| 98 | |||
| 99 | /** | ||
| 100 | * The clean call removes the 'vmid' from the reference list of | ||
| 101 | * each remote object indicated in 'id's. The sequence number is | ||
| 102 | * used to detect late clean calls. If the argument 'strong' is | ||
| 103 | * true, then the clean call is a result of a failed dirty call, | ||
| 104 | * thus the sequence number for the client 'vmid' needs to be | ||
| 105 | * remembered. | ||
| 106 | * | ||
| 107 | * @param ids IDs of objects to mark as unreferenced by calling client | ||
| 108 | * @param sequenceNum sequence number | ||
| 109 | * @param vmid client VMID | ||
| 110 | * @param strong make 'strong' clean call | ||
| 111 | * @throws RemoteException if clean call fails | ||
| 112 | */ | ||
| 113 | void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) | ||
| 114 | throws RemoteException; | ||
| 115 | } | ||
Binary file not shown.
| @@ -0,0 +1,77 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | package java.rmi.dgc; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * A lease contains a unique VM identifier and a lease duration. A | ||
| 29 | * Lease object is used to request and grant leases to remote object | ||
| 30 | * references. | ||
| 31 | */ | ||
| 32 | public final class Lease implements java.io.Serializable { | ||
| 33 | |||
| 34 | /** | ||
| 35 | * @serial Virtual Machine ID with which this Lease is associated. | ||
| 36 | * @see #getVMID | ||
| 37 | */ | ||
| 38 | private VMID vmid; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * @serial Duration of this lease. | ||
| 42 | * @see #getValue | ||
| 43 | */ | ||
| 44 | private long value; | ||
| 45 | /** indicate compatibility with JDK 1.1.x version of class */ | ||
| 46 | private static final long serialVersionUID = -5713411624328831948L; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Constructs a lease with a specific VMID and lease duration. The | ||
| 50 | * vmid may be null. | ||
| 51 | * @param id VMID associated with this lease | ||
| 52 | * @param duration lease duration | ||
| 53 | */ | ||
| 54 | public Lease(VMID id, long duration) | ||
| 55 | { | ||
| 56 | vmid = id; | ||
| 57 | value = duration; | ||
| 58 | } | ||
| 59 | |||
| 60 | /** | ||
| 61 | * Returns the client VMID associated with the lease. | ||
| 62 | * @return client VMID | ||
| 63 | */ | ||
| 64 | public VMID getVMID() | ||
| 65 | { | ||
| 66 | return vmid; | ||
| 67 | } | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Returns the lease duration. | ||
| 71 | * @return lease duration | ||
| 72 | */ | ||
| 73 | public long getValue() | ||
| 74 | { | ||
| 75 | return value; | ||
| 76 | } | ||
| 77 | } | ||
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,177 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.rmi.dgc; | ||
| 27 | |||
| 28 | import java.io.*; | ||
| 29 | import java.net.*; | ||
| 30 | import java.rmi.server.UID; | ||
| 31 | import java.security.*; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * A VMID is a identifier that is unique across all Java virtual | ||
| 35 | * machines. VMIDs are used by the distributed garbage collector | ||
| 36 | * to identify client VMs. | ||
| 37 | * | ||
| 38 | * @author Ann Wollrath | ||
| 39 | * @author Peter Jones | ||
| 40 | */ | ||
| 41 | public final class VMID implements java.io.Serializable { | ||
| 42 | |||
| 43 | /** array of bytes uniquely identifying this host */ | ||
| 44 | private static byte[] localAddr = computeAddressHash(); | ||
| 45 | |||
| 46 | /** | ||
| 47 | * @serial array of bytes uniquely identifying host created on | ||
| 48 | */ | ||
| 49 | private byte[] addr; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * @serial unique identifier with respect to host created on | ||
| 53 | */ | ||
| 54 | private UID uid; | ||
| 55 | |||
| 56 | /** indicate compatibility with JDK 1.1.x version of class */ | ||
| 57 | private static final long serialVersionUID = -538642295484486218L; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Create a new VMID. Each new VMID returned from this constructor | ||
| 61 | * is unique for all Java virtual machines under the following | ||
| 62 | * conditions: a) the conditions for uniqueness for objects of | ||
| 63 | * the class <code>java.rmi.server.UID</code> are satisfied, and b) an | ||
| 64 | * address can be obtained for this host that is unique and constant | ||
| 65 | * for the lifetime of this object. <p> | ||
| 66 | */ | ||
| 67 | public VMID() { | ||
| 68 | addr = localAddr; | ||
| 69 | uid = new UID(); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Return true if an accurate address can be determined for this | ||
| 74 | * host. If false, reliable VMID cannot be generated from this host | ||
| 75 | * @return true if host address can be determined, false otherwise | ||
| 76 | * @deprecated | ||
| 77 | */ | ||
| 78 | @Deprecated | ||
| 79 | public static boolean isUnique() { | ||
| 80 | return true; | ||
| 81 | } | ||
| 82 | |||
| 83 | /** | ||
| 84 | * Compute hash code for this VMID. | ||
| 85 | */ | ||
| 86 | public int hashCode() { | ||
| 87 | return uid.hashCode(); | ||
| 88 | } | ||
| 89 | |||
| 90 | /** | ||
| 91 | * Compare this VMID to another, and return true if they are the | ||
| 92 | * same identifier. | ||
| 93 | */ | ||
| 94 | public boolean equals(Object obj) { | ||
| 95 | if (obj instanceof VMID) { | ||
| 96 | VMID vmid = (VMID) obj; | ||
| 97 | if (!uid.equals(vmid.uid)) | ||
| 98 | return false; | ||
| 99 | if ((addr == null) ^ (vmid.addr == null)) | ||
| 100 | return false; | ||
| 101 | if (addr != null) { | ||
| 102 | if (addr.length != vmid.addr.length) | ||
| 103 | return false; | ||
| 104 | for (int i = 0; i < addr.length; ++ i) | ||
| 105 | if (addr[i] != vmid.addr[i]) | ||
| 106 | return false; | ||
| 107 | } | ||
| 108 | return true; | ||
| 109 | } else { | ||
| 110 | return false; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | /** | ||
| 115 | * Return string representation of this VMID. | ||
| 116 | */ | ||
| 117 | public String toString() { | ||
| 118 | StringBuffer result = new StringBuffer(); | ||
| 119 | if (addr != null) | ||
| 120 | for (int i = 0; i < addr.length; ++ i) { | ||
| 121 | int x = (int) (addr[i] & 0xFF); | ||
| 122 | result.append((x < 0x10 ? "0" : "") + | ||
| 123 | Integer.toString(x, 16)); | ||
| 124 | } | ||
| 125 | result.append(':'); | ||
| 126 | result.append(uid.toString()); | ||
| 127 | return result.toString(); | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Compute the hash an IP address. The hash is the first 8 bytes | ||
| 132 | * of the SHA digest of the IP address. | ||
| 133 | */ | ||
| 134 | private static byte[] computeAddressHash() { | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Get the local host's IP address. | ||
| 138 | */ | ||
| 139 | byte[] addr = java.security.AccessController.doPrivileged( | ||
| 140 | new PrivilegedAction<byte[]>() { | ||
| 141 | public byte[] run() { | ||
| 142 | try { | ||
| 143 | return InetAddress.getLocalHost().getAddress(); | ||
| 144 | } catch (Exception e) { | ||
| 145 | } | ||
| 146 | return new byte[] { 0, 0, 0, 0 }; | ||
| 147 | } | ||
| 148 | }); | ||
| 149 | |||
| 150 | byte[] addrHash; | ||
| 151 | final int ADDR_HASH_LENGTH = 8; | ||
| 152 | |||
| 153 | try { | ||
| 154 | /* | ||
| 155 | * Calculate message digest of IP address using SHA. | ||
| 156 | */ | ||
| 157 | MessageDigest md = MessageDigest.getInstance("SHA"); | ||
| 158 | ByteArrayOutputStream sink = new ByteArrayOutputStream(64); | ||
| 159 | DataOutputStream out = new DataOutputStream( | ||
| 160 | new DigestOutputStream(sink, md)); | ||
| 161 | out.write(addr, 0, addr.length); | ||
| 162 | out.flush(); | ||
| 163 | |||
| 164 | byte digest[] = md.digest(); | ||
| 165 | int hashlength = Math.min(ADDR_HASH_LENGTH, digest.length); | ||
| 166 | addrHash = new byte[hashlength]; | ||
| 167 | System.arraycopy(digest, 0, addrHash, 0, hashlength); | ||
| 168 | |||
| 169 | } catch (IOException ignore) { | ||
| 170 | /* can't happen, but be deterministic anyway. */ | ||
| 171 | addrHash = new byte[0]; | ||
| 172 | } catch (NoSuchAlgorithmException complain) { | ||
| 173 | throw new InternalError(complain.toString()); | ||
| 174 | } | ||
| 175 | return addrHash; | ||
| 176 | } | ||
| 177 | } | ||
| @@ -0,0 +1,10 @@ | |||
| 1 | <../../../../../mkconfig | ||
| 2 | |||
| 3 | TARG=\ | ||
| 4 | DGC.dis\ | ||
| 5 | Lease.dis\ | ||
| 6 | VMID.dis\ | ||
| 7 | |||
| 8 | DISBIN=$ROOT/java/dis/java/java/java/rmi/dgc | ||
| 9 | |||
| 10 | <$ROOT/mkfiles/mkjava | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | <!-- | ||
| 2 | Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | |||
| 5 | This code is free software; you can redistribute it and/or modify it | ||
| 6 | under the terms of the GNU General Public License version 2 only, as | ||
| 7 | published by the Free Software Foundation. Oracle designates this | ||
| 8 | particular file as subject to the "Classpath" exception as provided | ||
| 9 | by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | |||
| 11 | This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | accompanied this code). | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License version | ||
| 18 | 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | |||
| 21 | Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | or visit www.oracle.com if you need additional information or have any | ||
| 23 | questions. | ||
| 24 | --> | ||
| 25 | |||
| 26 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> | ||
| 27 | <html> | ||
| 28 | <body bgcolor="white"> | ||
| 29 | |||
| 30 | Provides classes and interface for RMI distributed | ||
| 31 | garbage-collection (DGC). When the RMI server returns an object to | ||
| 32 | its client (caller of the remote method), it tracks the remote | ||
| 33 | object's usage in the client. When there are no more references to the | ||
| 34 | remote object on the client, or if the reference's ``lease'' expires and | ||
| 35 | not renewed, the server garbage-collects the remote object. | ||
| 36 | |||
| 37 | <!-- | ||
| 38 | <h2>Package Specification</h2> | ||
| 39 | |||
| 40 | ##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT ##### | ||
| 41 | <ul> | ||
| 42 | <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a> | ||
| 43 | </ul> | ||
| 44 | |||
| 45 | <h2>Related Documentation</h2> | ||
| 46 | |||
| 47 | For overviews, tutorials, examples, guides, and tool documentation, please see: | ||
| 48 | <ul> | ||
| 49 | <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a> | ||
| 50 | </ul> | ||
| 51 | --> | ||
| 52 | |||
| 53 | @since JDK1.1 | ||
| 54 | </body> | ||
| 55 | </html> | ||