1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2008 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package ch.elca.el4j.services.remoting.socketfactory;
18
19 import java.io.IOException;
20 import java.io.Serializable;
21 import java.net.ServerSocket;
22 import java.net.Socket;
23 import java.rmi.server.RMISocketFactory;
24
25 /**
26 * This class is a custom {@link RMISocketFactory} allowing to define a SocketTimeout
27 * for the RMI connection.
28 * The value of this timeout can be set in the spring configuration file
29 * rmi-timeout.xml (in main/resources/mandatory).
30 *
31 * @svnLink $Revision: 3883 $;$Date: 2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/remoting_core/src/main/java/ch/elca/el4j/services/remoting/socketfactory/RMITimeoutSocketFactory.java $
32 *
33 * @author Dominik Zindel (DZI)
34 */
35 public class RMITimeoutSocketFactory extends RMISocketFactory implements
36 Serializable {
37
38 /**
39 *
40 */
41 private static final long serialVersionUID = 953865798975586465L;
42
43 /**
44 * The SocketTimeout.
45 */
46 private int m_timeout = 60000;
47
48 /**
49 * The constructor with the desired timeout as parameter.
50 *
51 * @param timeout
52 * The SocketTimeout.
53 */
54 public RMITimeoutSocketFactory(int timeout) {
55 super();
56 m_timeout = timeout;
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 @Override
63 public ServerSocket createServerSocket(int port) throws IOException {
64 ServerSocket socket = new ServerSocket(port);
65 socket.setSoTimeout(m_timeout);
66 return socket;
67 }
68
69 /**
70 * {@inheritDoc}
71 */
72 @Override
73 public Socket createSocket(String host, int port) throws IOException {
74 Socket socket = new Socket(host, port);
75 socket.setSoTimeout(m_timeout);
76 return socket;
77 }
78
79 }