1 /*
   2  * Copyright (c) 1997, 2019, 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 sun.rmi.server;
  27 
  28 import java.io.IOException;
  29 import java.io.NotSerializableException;
  30 import java.io.ObjectOutput;
  31 import java.rmi.*;
  32 import java.rmi.server.*;
  33 import java.rmi.activation.ActivationID;
  34 import sun.rmi.transport.LiveRef;
  35 
  36 /**
  37  * Server-side ref for a persistent remote impl.
  38  *
  39  * @author Ann Wollrath
  40  */
  41 @SuppressWarnings("serial") // Externalizable class w/o no-arg c'tor
  42 public class ActivatableServerRef extends UnicastServerRef2 {
  43 
  44     private static final long serialVersionUID = 2002967993223003793L;
  45 
  46     private ActivationID id;
  47 
  48     /**
  49      * Construct a Unicast server remote reference to be exported
  50      * on the specified port.
  51      */
  52     public ActivatableServerRef(ActivationID id, int port)
  53     {
  54         this(id, port, null, null);
  55     }
  56 
  57     /**
  58      * Construct a Unicast server remote reference to be exported
  59      * on the specified port.
  60      */
  61     public ActivatableServerRef(ActivationID id, int port,
  62                                 RMIClientSocketFactory csf,
  63                                 RMIServerSocketFactory ssf)
  64     {
  65         super(new LiveRef(port, csf, ssf));
  66         this.id = id;
  67     }
  68 
  69     /**
  70      * Returns the class of the ref type to be serialized
  71      */
  72     public String getRefClass(ObjectOutput out)
  73     {
  74         return "ActivatableServerRef";
  75     }
  76 
  77     /**
  78      * Return the client remote reference for this remoteRef.
  79      * In the case of a client RemoteRef "this" is the answer.
  80      * For  a server remote reference, a client side one will have to
  81      * found or created.
  82      */
  83     protected RemoteRef getClientRef() {
  84         return new ActivatableRef(id, new UnicastRef2(ref));
  85     }
  86 
  87     /**
  88      * Prevents serialization (because deserializaion is impossible).
  89      */
  90     public void writeExternal(ObjectOutput out) throws IOException {
  91         throw new NotSerializableException(
  92             "ActivatableServerRef not serializable");
  93     }
  94 }