package com.jqmobile.core.server.rmi.test;
/*
* @(#)RMIDirectSocketFactory.java 1.10 03/12/19
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.rmi.server.RMISocketFactory;
/**
* RMIDirectSocketFactory creates a direct socket connection to the specified
* port on the specified host.
*/
public class RMIDirectSocketFactory extends RMISocketFactory {
// static final Log proxyLog = Log.getLog("sun.rmi.transport.tcp.proxy",
// "transport", RMIDirectSocketFactory.logLevel);
//
// static int logLevel = LogStream.parseLevel(getLogLevel());
// private static String getLogLevel() {
// return (String) java.security.AccessController
// .doPrivileged(new sun.security.action.GetPropertyAction(
// "sun.rmi.transport.proxy.logLevel"));
// }
//
// private static int connectTimeout = getTimeout(
// "sun.rmi.transport.proxy.connectTimeout", 15000);
//
// private static int responseTimeout = getTimeout(
// "sun.rmi.transport.tcp.responseTimeout", 30 * 60 * 1000);
//
// private static int getTimeout(String prop, long defaultTimeout) {
// return ((Long) java.security.AccessController
// .doPrivileged(new GetLongAction(prop, defaultTimeout)))
// .intValue(); // default: 15 seconds
// }
private final static int responseTimeout=3 * 60 * 1000;
private final static int connectTimeout=60000;
public Socket createSocket(String host, int port) throws IOException {
Socket socket = new Socket();
SocketAddress endpoint = host != null ? new InetSocketAddress(host,
port)
: new InetSocketAddress(InetAddress.getByName(null), port);
// if (proxyLog.isLoggable(Log.BRIEF))
// proxyLog.log(Log.BRIEF, "createSocket: " + host.toString()
// + ",connectTimeout=" + connectTimeout + ",responseTimeout="
// + responseTimeout);
socket.setSoTimeout(responseTimeout);
socket.connect(endpoint, connectTimeout);
return socket;
}
public ServerSocket createServerSocket(int port) throws IOException {
return new ServerSocket(port);
}
}