1 package org.apache.commons.jcs3.auxiliary.remote.server;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.IOException;
23 import java.io.Serializable;
24 import java.net.InetSocketAddress;
25 import java.net.ServerSocket;
26 import java.net.Socket;
27 import java.rmi.server.RMISocketFactory;
28
29 /** For testing the custom socket factory configuration */
30 public class MockRMISocketFactory
31 extends RMISocketFactory
32 implements Serializable
33 {
34 /** Don't change */
35 private static final long serialVersionUID = 1056199478581218676L;
36
37 /** for testing automatic property configuration. */
38 private String testStringProperty;
39
40 /**
41 * @param host
42 * @param port
43 * @return Socket
44 * @throws IOException
45 */
46 @Override
47 public Socket createSocket( final String host, final int port )
48 throws IOException
49 {
50 // System.out.println( "Creating socket" );
51
52 final Socket socket = new Socket();
53 socket.setSoTimeout( 1000 );
54 socket.setSoLinger( false, 0 );
55 socket.connect( new InetSocketAddress( host, port ), 1000 );
56 return socket;
57 }
58
59 /**
60 * @param port
61 * @return ServerSocket
62 * @throws IOException
63 */
64 @Override
65 public ServerSocket createServerSocket( final int port )
66 throws IOException
67 {
68 // System.out.println( "Creating server socket" );
69
70 return new ServerSocket( port );
71 }
72
73 /**
74 * @param testStringProperty the testStringProperty to set
75 */
76 public void setTestStringProperty( final String testStringProperty )
77 {
78 this.testStringProperty = testStringProperty;
79 }
80
81 /**
82 * @return the testStringProperty
83 */
84 public String getTestStringProperty()
85 {
86 return testStringProperty;
87 }
88 }