当前位置: 首页>>代码示例>>Java>>正文


Java RMISocketFactory.setSocketFactory方法代码示例

本文整理汇总了Java中java.rmi.server.RMISocketFactory.setSocketFactory方法的典型用法代码示例。如果您正苦于以下问题:Java RMISocketFactory.setSocketFactory方法的具体用法?Java RMISocketFactory.setSocketFactory怎么用?Java RMISocketFactory.setSocketFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.rmi.server.RMISocketFactory的用法示例。


在下文中一共展示了RMISocketFactory.setSocketFactory方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    System.setProperty(RMISocketFactoryImpl.RMI_HOSTNAME_KEY, "localhost");
    RMISocketFactoryImpl impl = new RMISocketFactoryImpl();
    RMISocketFactory.setSocketFactory(impl);

    if (args.length > 0) {

    } else {
        Test.requireNameServer();
        Test.rebindTest();

        IntegerRMI remoteInt = new IntegerRMI();
        Test.rebind(TEST_INT_NAME, remoteInt);
    }

    Object o = Test.lookup(TEST_DATE_NAME);
    RemoteDate rd = (RemoteDate) o;
    System.out.println("The remote-date is: " + rd.getDate());

    o = Test.lookup(TEST_INT_NAME);
    RemoteInteger ri = (RemoteInteger) o;
    System.out.println("The remote-int  is: " + ri.getInt());

}
 
开发者ID:drankye,项目名称:haox,代码行数:25,代码来源:Test.java

示例2: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:UnderscoreHost.java

示例3: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6269166\n");
    RMISocketFactory.setSocketFactory(new SF());
    Remote impl = new ReuseDefaultPort();
    Remote stub = UnicastRemoteObject.exportObject(impl, 0);
    System.err.println("- exported object: " + stub);
    try {
        Registry registry = LocateRegistry.createRegistry(PORT);
        System.err.println("- exported registry: " + registry);
        System.err.println("TEST PASSED");
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:ReuseDefaultPort.java

示例4: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnEphemeralPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + port + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:UnderscoreHost.java

示例5: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6269166\n");
    RMISocketFactory.setSocketFactory(new SF());
    Remote impl = new ReuseDefaultPort();
    Remote stub = UnicastRemoteObject.exportObject(impl, 0);
    System.err.println("- exported object: " + stub);
    try {
        Registry registry = LocateRegistry.createRegistry(rmiPort);
        System.err.println("- exported registry: " + registry);
        System.err.println("TEST PASSED");
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ReuseDefaultPort.java

示例6: ensureRmiUseFixedPort

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
private static void ensureRmiUseFixedPort(final int port)
throws IOException, IllegalStateException {
	final RMISocketFactory prevSocketFactory = RMISocketFactory.getSocketFactory();
	if(prevSocketFactory == null) {
		RMISocketFactory.setSocketFactory(new FixedPortRmiSocketFactory(port));
	} else if(prevSocketFactory instanceof FixedPortRmiSocketFactory) {
		((FixedPortRmiSocketFactory) prevSocketFactory).setFixedPort(port);
	} else {
		throw new IllegalStateException("Invalid RMI socket factory was set");
	}
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:12,代码来源:ServiceUtil.java

示例7: LifecycleClient

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
private LifecycleClient(String serverIp, int rmiTimeout)
    throws RemoteException, NotBoundException {
  try {
    RMISocketFactory.setSocketFactory(new RMISocketFactory() {

      private final RMISocketFactory delegate =
          RMISocketFactory.getDefaultSocketFactory();

      @Override
      public Socket createSocket(String host, int port) throws IOException {
        final Socket socket = delegate.createSocket(host, port);
        if (rmiTimeout != 0) {
          socket.setSoTimeout(rmiTimeout);
        }
        return socket;
      }

      @Override
      public ServerSocket createServerSocket(int i) throws IOException {
        return delegate.createServerSocket(i);
      }
    });
  } catch (IOException e) {
    //ignored
  }
  this.lifecycleAgent = findLifecycleAgent(serverIp);
}
 
开发者ID:cloudiator,项目名称:lance,代码行数:28,代码来源:LifecycleClient.java

示例8: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String args[]) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME +
                      ":" + Registry.REGISTRY_PORT + "/" + NAME);
        /*
         * This test is coded to pass whether java.net.URI obeys
         * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
         *
         * If java.net.URI obeys RFC 3986, so host names may
         * contain underscores, then the Naming.lookup invocation
         * should succeed-- but the host actually connected to
         * must equal HOSTNAME.
         */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException(
                "java.rmi.Naming Parsing error:" +
                hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
        /*
         * If java.net.URI obeys RFC 2396, so host names must not
         * contain underscores, then the Naming.lookup invocation
         * should throw MalformedURLException-- so this is OK.
         */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }

}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:40,代码来源:UnderscoreHost.java

示例9: testSetSocketFactory002

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public final void testSetSocketFactory002() {
    try {
        RMISocketFactory.setSocketFactory(new MyRMISocketFactory());
    } catch (Throwable e) {
        fail("Should not raise an exception but raised: " + e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:8,代码来源:TestRMISocketFactory.java

示例10: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        boolean[] successful = new boolean[] { false };
        (new SomeReader(stream, successful)).start();

        // Wait for completion
        int nretries = 4;
        while (nretries-- > 0) {
            if (successful[0])
                break;
            Thread.sleep(DELAY);
        }

        if (successful[0]) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:66,代码来源:ReadTimeoutTest.java

示例11: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // HTTP direct to the server port
    System.setProperty("http.proxyHost", "127.0.0.1");

    // Set the socket factory.
    System.err.println("(installing HTTP-out socket factory)");
    HttpOutFactory fac = new HttpOutFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Set the HTTP port, at last.
        System.setProperty("http.proxyPort", port+"");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        Socket DoS = new Socket("127.0.0.1", port);
        // we hold the connection open until done with the test.

        // The test itself: make a remote call and see if it's blocked or
        // if it works
        //Thread.sleep(2000);
        System.err.println("(making RMI-through-HTTP call)");
        System.err.println("(typical test failure deadlocks here)");
        String result = stub.testCall("dummy load");

        System.err.println(" => " + result);
        if (!("OK".equals(result)))
            throw new Error("TEST FAILED: result not OK");
        System.err.println("Test passed.");

        // Clean up, including writing a byte to that connection just in
        // case an optimizer thought of optimizing it out of existence
        try {
            DoS.getOutputStream().write(0);
            DoS.getOutputStream().close();
        } catch (Throwable apathy) {
        }

    } finally {
        try {
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:BlockAcceptTest.java

示例12: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args)
    throws Exception
{
    // Make trouble for ourselves
    if (System.getSecurityManager() == null)
        System.setSecurityManager(new RMISecurityManager());

    // Flaky code alert - hope this is executed before TCPTransport.<clinit>
    System.setProperty("sun.rmi.transport.tcp.readTimeout", Integer.toString(DELAY));

    // Set the socket factory.
    System.err.println("(installing socket factory)");
    SomeFactory fac = new SomeFactory();
    RMISocketFactory.setSocketFactory(fac);

    // Create remote object
    TestImpl impl = new TestImpl();

    // Export and get which port.
    System.err.println("(exporting remote object)");
    TestIface stub = impl.export();
    Socket DoS = null;
    try {
        int port = fac.whichPort();

        // Sanity
        if (port == 0)
            throw new Error("TEST FAILED: export didn't reserve a port(?)");

        // Now, connect to that port
        //Thread.sleep(2000);
        System.err.println("(connecting to listening port on 127.0.0.1:" +
                           port + ")");
        DoS = new Socket("127.0.0.1", port);
        InputStream stream = DoS.getInputStream();

        // Read on the socket in the background
        CountDownLatch done = new CountDownLatch(1);
        (new SomeReader(stream, done)).start();

        // Wait for completion
        if (done.await(DELAY * 4, TimeUnit.SECONDS)) {
            System.err.println("TEST PASSED.");
        } else {
            throw new Error("TEST FAILED.");
        }

    } catch (InterruptedException ie) {
        throw new Error("Unexpected interrupt", ie);
    } finally {
        try {
            if (DoS != null)
                DoS.close();        // aborts the reader if still blocked
            impl.unexport();
        } catch (Throwable unmatter) {
        }
    }

    // Should exit here
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:ReadTimeoutTest.java

示例13: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
    
    if (args.length != 5) {
        System.err.println("5 Parameters needed...");
        System.exit(1);
    }

    System.setProperty("sun.rmi.transport.logLevel", "VERBOSE");
    System.setProperty("sun.rmi.transport.tcp.logLevel", "VERBOSE");
    System.setProperty("sun.rmi.transport.tcp.readTimeout", "1000");

    System.setProperty("http.proxyHost",args[1]);
    System.setProperty("http.proxyPort",args[2]);        
    
    if (args[4].equalsIgnoreCase("sun")) {
        try {
            RMISocketFactory.setSocketFactory(Util.getSunSocketFactory(args[0]));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } else if (args[4].equalsIgnoreCase("itc")) {
        Util.setITCSocketFactoryMode(args[0]);
    }
    
    String addr = args[3];
    if (addr == null) {
        addr = "10.100.2.246"; 
    }

    RemoteMap remoteMap = null;
    Registry remoteRegistry = null;

    String[] numbers = { "one", "two", "three", "four", "five", "six",
            "seven" };
    
    String[] data = { "pride", "envy", "gluttony", "lust", "anger",
            "greed", "sloth" };

    try {
            System.out
                    .println("RemoteMapClient locating RMI registry on remote host \""
                            + addr + "\".");
            remoteRegistry = LocateRegistry.getRegistry(addr);
            logger.info("RemoteMapClient looking up service \""
                    + RemoteMap.SERVICENAME + "\".");
            remoteMap = (RemoteMap) remoteRegistry
                    .lookup(RemoteMap.SERVICENAME);
    } catch (Exception e) {
        System.out
                .println("RemoteMapClient problem with RemoteMap, exception:\n   "
                        + e);
    }

    if (populateHashMap(data, numbers, addr, remoteMap)) {
        System.out
                .println("RemoteMapClient HashMap successfully populated...");
    }

    // getCall("one",addr,remoteMap);
    if (data.length == sizeCall(remoteMap)) {
        logger.info("RemoteMapClient HashMap size correct...");
    }

    if (checkPopulatedHashMap(data, numbers, addr, remoteMap)) {
        logger.info("RemoteMapClient HashMap check passed...");
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:68,代码来源:RemoteHashClient.java

示例14: main

import java.rmi.server.RMISocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
    
    System.setProperty("http.proxyHost","10.100.2.1");
    System.setProperty("http.proxyPort","3128");
    System.setProperty("sun.rmi.transport.logLevel", "VERBOSE");
    System.setProperty("sun.rmi.transport.tcp.logLevel", "VERBOSE");
    System.setProperty("sun.rmi.transport.tcp.readTimeout", "1000");
    
    try {
        RMISocketFactory.setSocketFactory(new RMIHttpToCGISocketFactory());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    
    String addr = "10.100.2.246";
    
    Calculator remoteCalc = null;
    Registry remoteRegistry = null;
    
    try {
        logger.info("RemoteCalculatorClient locating RMI registry on remote host \""+ addr + "\".");
        remoteRegistry = LocateRegistry.getRegistry(addr);
        
        logger.info("RemoteCalculatorClient looking up service \""+ RemoteCalculator.SERVICENAME + "\".");
        remoteCalc = (Calculator) remoteRegistry.lookup(RemoteCalculator.SERVICENAME);
        
        int[][] a = new int[][] {{9,2},{6,4}};
        int[][] b = new int[][] {{1,4},{1,5}}; 
        
        remoteCalc.setMatrixA(a);
        remoteCalc.setMatrixB(b);
        
        System.out.println("Matrix A");
        System.out.println(Arrays.toString(a[0]));
        System.out.println(Arrays.toString(a[1]));
        System.out.println();
        
        System.out.println("Matrix B");
        System.out.println(Arrays.toString(b[0]));
        System.out.println(Arrays.toString(b[1]));
        System.out.println();
        
        System.out.println("Result Matrix (multiply)");
        System.out.println(Arrays.toString(remoteCalc.multiplyMatrixAB()[0]));
        System.out.println(Arrays.toString(remoteCalc.multiplyMatrixAB()[1]));
        System.out.println();
        
        System.out.println("Result Matrix (add)");
        System.out.println(Arrays.toString(remoteCalc.sumMatrixAB()[0]));
        System.out.println(Arrays.toString(remoteCalc.sumMatrixAB()[1]));
        System.out.println();
        
        
        System.out.println("Vector");
        Vector v = new Vector(4);
        v.add(new Double(50.21));
        v.add(new Double(2000.125));
        v.add(new Double(196.15));
        v.add(new Double(36.95));
        
        remoteCalc.setVectorA(v);
        
        System.out.println(v.toString());
        System.out.println();
        
        System.out.println("Standard Deviation: "+remoteCalc.getDevProm()[0]);
        System.out.println("Average: "+remoteCalc.getDevProm()[1]);
        
    } catch (Exception e) {
        logger.info("RemoteCalculatorClient problem with RemoteCalculator, exception:\n "+ e);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:73,代码来源:RemoteCalculatorClient.java


注:本文中的java.rmi.server.RMISocketFactory.setSocketFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。