Path: blob/master/src/java.rmi/share/classes/java/rmi/registry/Registry.java
41159 views
/*1* Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package java.rmi.registry;2526import java.rmi.AccessException;27import java.rmi.AlreadyBoundException;28import java.rmi.NotBoundException;29import java.rmi.Remote;30import java.rmi.RemoteException;3132/**33* <code>Registry</code> is a remote interface to a simple remote34* object registry that provides methods for storing and retrieving35* remote object references bound with arbitrary string names. The36* <code>bind</code>, <code>unbind</code>, and <code>rebind</code>37* methods are used to alter the name bindings in the registry, and38* the <code>lookup</code> and <code>list</code> methods are used to39* query the current name bindings.40*41* <p>In its typical usage, a <code>Registry</code> enables RMI client42* bootstrapping: it provides a simple means for a client to obtain an43* initial reference to a remote object. Therefore, a registry's44* remote object implementation is typically exported with a45* well-known address, such as with a well-known {@link46* java.rmi.server.ObjID#REGISTRY_ID ObjID} and TCP port number47* (default is {@link #REGISTRY_PORT 1099}).48*49* <p>The {@link LocateRegistry} class provides a programmatic API for50* constructing a bootstrap reference to a <code>Registry</code> at a51* remote address (see the static <code>getRegistry</code> methods)52* and for creating and exporting a <code>Registry</code> in the53* current VM on a particular local address (see the static54* <code>createRegistry</code> methods).55*56* <p>A <code>Registry</code> implementation may choose to restrict57* access to some or all of its methods (for example, methods that58* mutate the registry's bindings may be restricted to calls59* originating from the local host). If a <code>Registry</code>60* method chooses to deny access for a given invocation, its61* implementation may throw {@link java.rmi.AccessException}, which62* (because it extends {@link java.rmi.RemoteException}) will be63* wrapped in a {@link java.rmi.ServerException} when caught by a64* remote client.65*66* <p>The names used for bindings in a <code>Registry</code> are pure67* strings, not parsed. A service which stores its remote reference68* in a <code>Registry</code> may wish to use a package name as a69* prefix in the name binding to reduce the likelihood of name70* collisions in the registry.71*72* @author Ann Wollrath73* @author Peter Jones74* @since 1.175* @see LocateRegistry76*/77public interface Registry extends Remote {7879/** Well known port for registry. */80public static final int REGISTRY_PORT = 1099;8182/**83* Returns the remote reference bound to the specified84* <code>name</code> in this registry.85*86* @param name the name for the remote reference to look up87*88* @return a reference to a remote object89*90* @throws NotBoundException if <code>name</code> is not currently bound91*92* @throws RemoteException if remote communication with the93* registry failed; if exception is a <code>ServerException</code>94* containing an <code>AccessException</code>, then the registry95* denies the caller access to perform this operation96*97* @throws AccessException if this registry is local and it denies98* the caller access to perform this operation99*100* @throws NullPointerException if <code>name</code> is <code>null</code>101*/102public Remote lookup(String name)103throws RemoteException, NotBoundException, AccessException;104105/**106* Binds a remote reference to the specified <code>name</code> in107* this registry.108*109* @param name the name to associate with the remote reference110* @param obj a reference to a remote object (usually a stub)111*112* @throws AlreadyBoundException if <code>name</code> is already bound113*114* @throws RemoteException if remote communication with the115* registry failed; if exception is a <code>ServerException</code>116* containing an <code>AccessException</code>, then the registry117* denies the caller access to perform this operation (if118* originating from a non-local host, for example)119*120* @throws AccessException if this registry is local and it denies121* the caller access to perform this operation122*123* @throws NullPointerException if <code>name</code> is124* <code>null</code>, or if <code>obj</code> is <code>null</code>125*/126public void bind(String name, Remote obj)127throws RemoteException, AlreadyBoundException, AccessException;128129/**130* Removes the binding for the specified <code>name</code> in131* this registry.132*133* @param name the name of the binding to remove134*135* @throws NotBoundException if <code>name</code> is not currently bound136*137* @throws RemoteException if remote communication with the138* registry failed; if exception is a <code>ServerException</code>139* containing an <code>AccessException</code>, then the registry140* denies the caller access to perform this operation (if141* originating from a non-local host, for example)142*143* @throws AccessException if this registry is local and it denies144* the caller access to perform this operation145*146* @throws NullPointerException if <code>name</code> is <code>null</code>147*/148public void unbind(String name)149throws RemoteException, NotBoundException, AccessException;150151/**152* Replaces the binding for the specified <code>name</code> in153* this registry with the supplied remote reference. If there is154* an existing binding for the specified <code>name</code>, it is155* discarded.156*157* @param name the name to associate with the remote reference158* @param obj a reference to a remote object (usually a stub)159*160* @throws RemoteException if remote communication with the161* registry failed; if exception is a <code>ServerException</code>162* containing an <code>AccessException</code>, then the registry163* denies the caller access to perform this operation (if164* originating from a non-local host, for example)165*166* @throws AccessException if this registry is local and it denies167* the caller access to perform this operation168*169* @throws NullPointerException if <code>name</code> is170* <code>null</code>, or if <code>obj</code> is <code>null</code>171*/172public void rebind(String name, Remote obj)173throws RemoteException, AccessException;174175/**176* Returns an array of the names bound in this registry. The177* array will contain a snapshot of the names bound in this178* registry at the time of the given invocation of this method.179*180* @return an array of the names bound in this registry181*182* @throws RemoteException if remote communication with the183* registry failed; if exception is a <code>ServerException</code>184* containing an <code>AccessException</code>, then the registry185* denies the caller access to perform this operation186*187* @throws AccessException if this registry is local and it denies188* the caller access to perform this operation189*/190public String[] list() throws RemoteException, AccessException;191}192193194