【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“VirtualSocketFactory.java”一文,供大家参考学习!
package rmiconnection;
import java.io.*;
import java.net.*;
import java.rmi.server.*;
import multiplexer.*;
public class VirtualSocketFactory extends RMISocketFactory {
private VirtualClientSocketFactory clientFactory;
private VirtualServerSocketFactory serverFactory;
/**
* Constructor
*/
public VirtualSocketFactory() {
clientFactory = new VirtualClientSocketFactory();
serverFactory = new VirtualServerSocketFactory();
} // constructor
/**
* Register a <code>Multiplexer</code> that can be used to
* create <code>Socket<code> objects.
* @param mux The <code>Multiplexer</code> object to
* register.
*/
public void registerClientMultiplexer(Multiplexer mux) {
clientFactory.registerMultiplexer(mux);
} // registerMultiplexer(Multiplexer)
/**
* Unregister a <code>Multiplexer</code> object so that this
* Factory object will stop using it to create
* <code>Socket</code> objects.
* @param mux The <code>Multiplexer</code> object to
* unregister.
*/
public void unregisterClientMultiplexer(Multiplexer mux) {
clientFactory.unregisterMultiplexer(mux);
} // unregisterMultiplexer(Multiplexer)
/**
* Create a client socket connected to the specified host
* and port.
*<p>
* If the port number is -1 and host name resolves to a
* network address that matches one of the registered
* <code>Multiplexer</code> object, then this method ignores the
* port number passed to it and uses the
* <code>Multiplexer</code> to create a virtual connection.
* Otherwise it create a real connection using rmi's
* default mechanism.
*/
public Socket createSocket(String host, int port)
throws IOException {
return clientFactory.createSocket(host, port);
} // createSocket(String, int)
/**
* Register a <code>Multiplexer</code> object so that this
* Factory object will use it to create
* <code>ServerSocket</code> objects.
* @param mux The <code>Multiplexer</code> object to
* register.
*/
public void registerServerMultiplexer(Multiplexer mux) {
serverFactory.registerMultiplexer(mux);
} // registerMultiplexer(Multiplexer)
/**
* Unregister a <code>Multiplexer</code> object so that this
* Factory object will stop using it to create
* <code>ServerSocket</code> objects.
* @param mux The <code>Multiplexer</code> object to
* unregister.
*/
public void unregisterServerMultiplexer(Multiplexer mux) {
serverFactory.unregisterMultiplexer(mux);
} // unregisterMultiplexer(Multiplexer)
/**
* Create a server socket. If the given port number is -1,
* then it creats a server socket that accepts connections
* from registered <code>Multiplexer</code> objects.
* Otherwise, it creates a standard
* <code>ServerSocket</code> that accepts actual
* connections.
*/
public ServerSocket createServerSocket(int port)
throws IOException {
return serverFactory.createServerSocket(port);
} // createServerSocket(int)
/**
* Use the given name to a string of the form
*<br>
* //host:-1/name
*<br>
* This string can be used to register an object with a
* name registry.
*/
public String makeRegistryString(String name)
throws UnknownHostException {
return serverFactory.makeRegistryString(name);
} // makeRegistryString(String)
} // class VirtualSocketFactory
上一篇:
VirtualServerSocketFactory.java
下一篇:
关于大学英语教学