Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

Proxy.java

Go to the documentation of this file.
00001 /**************************************************************************
00002  Copyright (c) 2000-2001, Tony Garnock-Jones
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without
00006  modification, are permitted provided that the following conditions are
00007  met:
00008 
00009      * Redistributions of source code must retain the above copyright
00010        notice, this list of conditions and the following disclaimer.
00011 
00012      * Redistributions in binary form must reproduce the above
00013        copyright notice, this list of conditions and the following
00014        disclaimer in the documentation and/or other materials provided
00015        with the distribution.
00016 
00017      * Neither the names of the copyright holders nor the names of this
00018        software's contributors may be used to endorse or promote
00019        products derived from this software without specific prior
00020        written permission.
00021 
00022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
00026  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 **************************************************************************/
00034 
00035 package org.hebe.mps;
00036 
00037 import java.io.*;
00038 import java.net.*;
00039 
00040 /**
00041  * This is the base class of all client-side MPS object handles. It
00042  * maintains a Connection object and an InputStream and an
00043  * OutputStream. There is very little behaviour on this object - the
00044  * automatically-generated subclasses provide all the functionality by
00045  * making use of this object's protected member variables.
00046  *
00047  * @author Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
00048  * @see org.hebe.mps.Connection
00049  * @see org.hebe.mps.InputStream
00050  * @see org.hebe.mps.OutputStream
00051  */
00052 public class Proxy {
00053     /** The connection to the remote object server. */
00054     private org.hebe.mps.Connection _connection;
00055     /** Pipe used when sending messages to the remote server. */
00056     private org.hebe.mps.OutputStream _output;
00057     /** Pipe used when receiving messages from the remote server. */
00058     private org.hebe.mps.InputStream _input;
00059 
00060     /**
00061      * Only invoked by subclass constructors. Creates a connection to
00062      * the named object, possibly using the naming service passed in,
00063      * if it is not null.
00064      *
00065      * @param resolvedName the name of the server to create a proxy for
00066      * @exception MPSException if anything goes wrong
00067      */
00068     protected Proxy(String resolvedName)
00069         throws MPSException
00070     {
00071         _connection = new Connection(resolvedName);
00072         _input = new InputStream(_connection);
00073         _output = new OutputStream(_connection);
00074     }
00075 
00076     /**
00077      * Disconnects this client proxy from the server. Closes the
00078      * socket. It'd be nice if eventually this was reversible -
00079      * subsequent calls to methods on the proxy should transparently
00080      * reconnect and succeed, but currently once the connection is
00081      * gone, it's gone.
00082      *
00083      * @exception MPSException if anything goes wrong
00084      */
00085     public void _disconnect_proxy() throws MPSException {
00086         _connection.close();
00087     }
00088 
00089     /**
00090      * Retrieve the canonical name of the server this proxy is
00091      * connected to. Used (occasionally) to pass references to MPS
00092      * objects around between MPS interfaces.
00093      *
00094      * @return the canonical name of the connected server
00095      * @see org.hebe.mps.OutputStream#writeReference
00096      */
00097     protected String getReference() {
00098         return _connection.getResolvedName();
00099     }
00100 
00101     /**
00102      * Returns a handle on this proxy's output stream for
00103      * communication with the server.
00104      */
00105     protected org.hebe.mps.OutputStream getOutputStream() {
00106         _output.writeint(_connection.getOid());
00107         return _output;
00108     }
00109 
00110     /**
00111      * Returns a handle on this proxy's input stream for
00112      * communication from the server.
00113      */
00114     protected org.hebe.mps.InputStream getInputStream()
00115         throws MPSException
00116     {
00117         if (_input.readint() != _connection.getOid()) {
00118             throw new MPSException("OID mismatch in Proxy.getInputStream");
00119         }
00120         return _input;
00121     }
00122 }

Generated at Wed Aug 15 01:05:34 2001 for mps-java by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001