View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2026 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix.rmi;
19  
20  import java.io.IOException;
21  import java.io.Serializable;
22  import java.net.ServerSocket;
23  import java.rmi.server.RMIServerSocketFactory;
24  
25  import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
26  
27  /**
28   * An implementation of {@link RMIServerSocketFactory}.
29   *
30   * @see AFRMISocketFactory
31   */
32  @SuppressFBWarnings({
33      "SING_SINGLETON_IMPLEMENTS_SERIALIZABLE", "SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR"})
34  public class DefaultRMIServerSocketFactory implements RMIServerSocketFactory, Serializable {
35    private static final long serialVersionUID = 1L;
36    private static final DefaultRMIServerSocketFactory INSTANCE = new DefaultRMIServerSocketFactory();
37  
38    /**
39     * Creates a new {@link DefaultRMIClientSocketFactory}.
40     */
41    public DefaultRMIServerSocketFactory() {
42      super();
43    }
44  
45    /**
46     * Returns the singleton instance for DefaultRMIServerSocketFactory.
47     *
48     * @return The singleton.
49     */
50    public static DefaultRMIServerSocketFactory getInstance() {
51      return INSTANCE;
52    }
53  
54    @Override
55    @SuppressFBWarnings("UNENCRYPTED_SERVER_SOCKET")
56    public ServerSocket createServerSocket(int port) throws IOException {
57      ServerSocket socket = new ServerSocket(port); // NOPMD.VariableCanBeInlined
58      // socket.setSoTimeout(60 * 60 * 1000);
59      return socket;
60    }
61  
62    // we must implement this (see RMIServerSocketFactory)
63    @Override
64    public boolean equals(Object obj) {
65      return obj instanceof DefaultRMIServerSocketFactory;
66    }
67  
68    // we must implement this (see RMIServerSocketFactory)
69    @Override
70    public int hashCode() {
71      return 1;
72    }
73  }