1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 10:25:32 +02:00

[289678][api][breaking] ServerSocket creation in multiple IP addresses

This commit is contained in:
David McKnight 2010-04-16 15:29:08 +00:00
parent 0d4d492e6c
commit d16194268a
2 changed files with 61 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2009 IBM Corporation and others. * Copyright (c) 2002, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -24,6 +24,7 @@
* Noriaki Takatsu (IBM) - [242968] [multithread] serverSocket must be closed when an exception happens in Accept * Noriaki Takatsu (IBM) - [242968] [multithread] serverSocket must be closed when an exception happens in Accept
* David McKnight (IBM) - [257321] [dstore] "Error binding socket" should include port of the failed socket * David McKnight (IBM) - [257321] [dstore] "Error binding socket" should include port of the failed socket
* Noriaki Takatsu (IBM) - [283656] [dstore][multithread] Serviceability issue * Noriaki Takatsu (IBM) - [283656] [dstore][multithread] Serviceability issue
* Noriaki Takatsu (IBM) - [289678][api][breaking] ServerSocket creation in multiple IP addresses
*******************************************************************************/ *******************************************************************************/
package org.eclipse.dstore.core.server; package org.eclipse.dstore.core.server;
@ -139,6 +140,24 @@ public class ConnectionEstablisher
{ {
setup(port, timeout, ticket); setup(port, timeout, ticket);
} }
/**
* Creates a ConnectionEstablisher. Communication occurs
* on the specified port and the specified IP address,
* a timeout value indicates the idle wait time
* before shutting down, and ticket specified the required
* ticket for a client to present in order to work with the DataStore.
*
* @param port the number of the socket port
* @param backlog listen backlog
* @param bindAddr the local IP address to bind to
* @param timeout the idle duration to wait before shutting down
* @param ticket validation id required by the client to access the DataStore
*/
public ConnectionEstablisher(String port, int backlog, InetAddress bindAddr, String timeout, String ticket)
{
setup(port, backlog, bindAddr, timeout, ticket);
}
/** /**
@ -282,7 +301,7 @@ public class ConnectionEstablisher
private ServerSocket createSocket(String portStr) throws UnknownHostException private ServerSocket createSocket(String portStr, int backlog, InetAddress bindAddr) throws UnknownHostException
{ {
ServerSocket serverSocket = null; ServerSocket serverSocket = null;
SSLContext sslContext = null; SSLContext sslContext = null;
@ -328,7 +347,7 @@ public class ConnectionEstablisher
{ {
try try
{ {
serverSocket = sslContext.getServerSocketFactory().createServerSocket(i); serverSocket = sslContext.getServerSocketFactory().createServerSocket(i, backlog, bindAddr);
} }
catch (Exception e) catch (Exception e)
{ {
@ -336,7 +355,7 @@ public class ConnectionEstablisher
} }
else else
{ {
serverSocket = new ServerSocket(i); serverSocket = new ServerSocket(i, backlog, bindAddr);
} }
} }
catch (Exception e) catch (Exception e)
@ -363,7 +382,7 @@ public class ConnectionEstablisher
{ {
try try
{ {
serverSocket = sslContext.getServerSocketFactory().createServerSocket(port); serverSocket = sslContext.getServerSocketFactory().createServerSocket(port, backlog, bindAddr);
} }
catch (BindException e){ catch (BindException e){
_msg = ServerReturnCodes.RC_BIND_ERROR + " on port " + port + ": " + e.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$ _msg = ServerReturnCodes.RC_BIND_ERROR + " on port " + port + ": " + e.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$
@ -378,7 +397,7 @@ public class ConnectionEstablisher
{ {
try try
{ {
serverSocket = new ServerSocket(port); serverSocket = new ServerSocket(port, backlog, bindAddr);
} }
catch (BindException e){ catch (BindException e){
_msg = ServerReturnCodes.RC_BIND_ERROR + " on port " + port + ": " + e.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$ _msg = ServerReturnCodes.RC_BIND_ERROR + " on port " + port + ": " + e.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$
@ -392,7 +411,7 @@ public class ConnectionEstablisher
} }
return serverSocket; return serverSocket;
} }
/** /**
* Create the DataStore and initializes it's handlers and communications. * Create the DataStore and initializes it's handlers and communications.
* *
@ -401,6 +420,20 @@ public class ConnectionEstablisher
* @param ticketStr validation id required by the client to access the DataStore * @param ticketStr validation id required by the client to access the DataStore
*/ */
private void setup(String portStr, String timeoutStr, String ticketStr) private void setup(String portStr, String timeoutStr, String ticketStr)
{
setup(portStr, 50, null, timeoutStr, ticketStr);
}
/**
* Create the DataStore and initializes it's handlers and communications.
*
* @param portStr the number of the socket port
* @param backlog listen backlog
* @param bindAddr the local IP address to bind to
* @param timeoutStr the idle duration to wait before shutting down
* @param ticketStr validation id required by the client to access the DataStore
*/
private void setup(String portStr, int backlog, InetAddress bindAddr, String timeoutStr, String ticketStr)
{ {
_maxConnections = 1; _maxConnections = 1;
@ -435,7 +468,7 @@ public class ConnectionEstablisher
try try
{ {
_serverSocket = createSocket(portStr); _serverSocket = createSocket(portStr, backlog, bindAddr);
if (_serverSocket == null) if (_serverSocket == null)
{ {
_continue = false; _continue = false;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2008 IBM Corporation and others. * Copyright (c) 2002, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,10 +16,12 @@
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability * David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
* David McKnight (IBM) - [225507][api][breaking] RSE dstore API leaks non-API types * David McKnight (IBM) - [225507][api][breaking] RSE dstore API leaks non-API types
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed * David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
* Noriaki Takatsu (IBM) - [289678][api][breaking] ServerSocket creation in multiple IP addresses
*******************************************************************************/ *******************************************************************************/
package org.eclipse.dstore.core.server; package org.eclipse.dstore.core.server;
import java.net.InetAddress;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.eclipse.dstore.internal.core.server.ServerReturnCodes; import org.eclipse.dstore.internal.core.server.ServerReturnCodes;
@ -157,6 +159,23 @@ public class Server implements Runnable
{ {
_establisher = new ConnectionEstablisher(port, timeout, ticket); _establisher = new ConnectionEstablisher(port, timeout, ticket);
} }
/**
* Creates a new Server that waits on the specified socket port and
* the specified IP address with the backlog for
* the specified time interval before shutting down.
*
* @param port the number of the socket port to wait on
* @param backlog listen backlog
* @param bindAddr the local IP address to bind to
* @param timeout the idle time to wait before shutting down
* @param ticket the ticket that the client needs to interact with the DataStore
*/
public Server(String port, int backlog, InetAddress bindAddr, String timeout, String ticket)
{
_establisher = new ConnectionEstablisher(port, backlog, bindAddr, timeout, ticket);
}
/** /**