Methods Summary |
---|
void | _initializeService()
synchronized (managedPortsTable) {
// put the port in stable so that exists(port) returns true
managedPortsTable.put(config.getPort(), this);
}
// open channel and bind its ServerSocket
sschan = ServerSocketChannel.open();
ss = sschan.socket();
if (setReuseAddress) {
ss.setReuseAddress(true);
}
if (config.getBacklog() > 0) {
ss.bind(config.getSocketAddress(), config.getBacklog());
} else {
ss.bind(config.getSocketAddress());
}
|
void | _reInitializeService()
ASSelectorProvider provider =
(ASSelectorProvider) SelectorProvider.provider();
provider.clear(config.getPort());
synchronized (managedPortsTable) {
// put the port in stable so that exists(port) returns true
managedPortsTable.remove(config.getPort());
}
try {
if (this.sel != null) {
this.sel.close();
}
} catch (Exception e) {
logger.log(Level.FINEST, e.getMessage(), e);
}
int oldPort = config.getPort();
config.init();
/** In retrospect, the reInitialization is not that necessary.
Commenting this out for now. Keeping this code within
the comment so that it can be turned on later.
Reinitialization will be required, when we automatically
stop containers that are idle.
if (config.getPort() == oldPort) {
_initializeService();
}
**/
|
void | _socketServiceNotified(int port)
if (state == NOTSTARTED) {
// No one has started it so far.
if (!ServerEntryHelper.isNotifiedByPortEntryContext(port)) {
state = SERVICENOTIFIED;
}
}
|
void | _waitForServiceStartUp(java.net.Socket s)
if ( entryBeingProcessed() ) {
int localPort = s.getLocalPort();
// If client is in this JVM, dont wait
synchronized ( acceptLock ) {
while ( entryBeingProcessed() &&
! ASSocketService.hasClientSocketLocalPorts(s) ) {
if ( logger.isLoggable(Level.FINE) ) {
logger.fine("In ASSocketService.waitForServiceStartUp for localport " + localPort);
}
try {
acceptLock.wait();
} catch ( Exception ex ) {}
}
}
}
|
void | _waitOnClientConnection()
if (entryBeingProcessed()) {
synchronized (acceptLock) {
try {
while (entryBeingProcessed()) {
acceptLock.wait();
}
} catch (InterruptedException ie) {
}
}
}
|
static void | clientSocketConnected(int port, int localPort)
boolean toAdd = true;
if ( peMain.isStartingUp() ) {
if ( logger.isLoggable(Level.FINE) ) {
logger.fine("In ASSocketService.clientSocketConnected, adding port "
+ localPort);
}
synchronized ( peMain ) {
putClientSocketLocalPort(port, localPort);
toAdd = false;
peMain.notifyAll();
}
}
ASSocketService service = ASSocketService.get(port);
if (service != null && service.entryBeingProcessed()) {
synchronized ( service.acceptLock ) {
if (toAdd) {
putClientSocketLocalPort(port, localPort);
}
service.acceptLock.notifyAll();
}
}
|
static boolean | close(int port, java.net.ServerSocket sock, java.nio.channels.ServerSocketChannel channel)
ASSocketService savedSS = null;
if (port > 0) {
savedSS = ASSocketService.get(port);
if (savedSS != null) { //If managed by socket service
if (savedSS.entryBeingProcessed()) {
// Return and dont close
ASSelectorProvider pr = (ASSelectorProvider)
SelectorProvider.provider();
pr.setPortState(port, ASSelectorProvider.PORT_BOUND);
return false;
}
}
}
boolean closed = false;
try {
if (channel != null) {
if (channel.isOpen()) {
closed = true;
channel.close();
}
}
if (sock != null) {
if (sock.isClosed() == false) {
closed = true;
sock.close();
}
}
} finally {
if (savedSS != null && closed) {
ASSocketService.reInitializeService(port);
}
}
return true;
|
java.nio.channels.Selector | createListeningSelector()
try {
sschan.configureBlocking(false);
this.sel = Selector.open();
sschan.register(sel, SelectionKey.OP_ACCEPT);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
return this.sel;
|
boolean | entryBeingProcessed()
return state != STARTED;
|
static boolean | exists(int port)
return managedPortsTable.containsKey(port);
|
public void | generateEntryContext(java.lang.Object context)
if ( logger.isLoggable(Level.FINE) ) {
logger.fine("In ASSocketService.generateEntryContext for context " + context);
}
ServerEntryHelper.generatePortEntryContext((Integer) context);
|
static com.sun.enterprise.server.ss.ASSocketService | get(int port)
return managedPortsTable.get(port);
|
static java.net.ServerSocket | getServerSocket(int port)
ASSocketService a = managedPortsTable.get(port);
return a.ss;
|
static java.nio.channels.ServerSocketChannel | getServerSocketChannel(int port)
ASSocketService a = managedPortsTable.get(port);
return a.sschan;
|
static boolean | hasClientSocketLocalPorts(java.net.Socket s)
ASServerSocket ss = (ASServerSocket) getServerSocket(s.getLocalPort());
return ss.hasClientSocketLocalPorts();
|
static void | initialize()
if ( peMain == null ) {
peMain = com.sun.enterprise.server.PEMain.getInstance();
}
|
static boolean | isLocalClient(java.net.Socket s)
return isLocalClient(s.getInetAddress());
|
static boolean | isLocalClient(java.net.InetAddress remoteAddr)
// Check if s is connected to a remote client (on a different machine)
return ( remoteAddr.equals(localHost)
|| remoteAddr.isSiteLocalAddress()
|| remoteAddr.isLinkLocalAddress()
|| remoteAddr.isLoopbackAddress()
|| remoteAddr.isAnyLocalAddress());
|
static boolean | isServerStartingUp()
return peMain.isStartingUp();
|
static boolean | isServerStartingUp(int port)
if (isServerStartingUp() == true) {
return true;
}
if (port > 0 ) {
ASSocketService savedSS = ASSocketService.get(port);
if (savedSS != null) {
return savedSS.entryBeingProcessed();
}
}
return false;
|
public static java.nio.channels.SelectionKey | keyFor(java.nio.channels.SelectableChannel channel, java.nio.channels.Selector sel)
return channel.keyFor(((ASSelector) sel).getSelector());
|
static void | putClientSocketLocalPort(int serverPort, int localPort)
if (exists(serverPort)) {
ASServerSocket ss = (ASServerSocket) getServerSocket(serverPort);
ss.addClientSocketLocalPort(localPort);
}
|
static void | reInitializeService(int port)
ASSocketService savedSS = ASSocketService.get(port);
if (savedSS != null) {
savedSS._reInitializeService();
}
|
static void | removeListeningSelector(int port)
try {
ASSocketService savedSS = get(port);
if (savedSS.sel != null) {
savedSS.sel.close();
savedSS.sschan.configureBlocking(true);
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
|
public static boolean | socketServiceNotified(int port)
ASSocketService ss = ASSocketService.get(port);
if (ss != null) {
InvocationManager im = Switch.getSwitch().getInvocationManager();
//System.out.println("Startup invocation :" + im.isStartupInvocation());
ss._socketServiceNotified(port);
return im.isStartupInvocation();
} else {
return true;
}
|
void | start()
try {
config.init();
_initializeService();
if (config.getStartSelector() == true) {
Selector select = createListeningSelector();
(new EntryPointThread(select)).start();
} else {
// Socket service doesnt need to handle the
// lifecycle.
this.state = STARTED;
}
if ( logger.isLoggable(Level.FINE) ) {
logger.fine("ASSocketService Successfully started for " + config);
}
} catch(IOException ie){
String i18nMsg = localStrings.getString(
"socketservice.port_conflict", new Object[]{String.valueOf(config.getPort())});
throw new PortConflictException(config.getPort(),i18nMsg, ie);
}
|
public static void | triggerServerExit()
synchronized (lock) {
triggered = true;
lock.notifyAll();
}
|
public static void | waitForClientNotification()
synchronized (lock) {
if (triggered == false) {
try {
lock.wait(TIMEOUT);
} catch (Exception e ) {
e.printStackTrace();
}
}
}
|
static void | waitForServiceStartUp(java.net.Socket s)
ASSocketService savedService = get(s.getLocalPort());
if ( savedService != null ) {
savedService._waitForServiceStartUp(s);
}
|
static void | waitOnAccept(java.nio.channels.SocketChannel sc)
// Redundant peMain.isStartingUp() is required since sc.socket()
// has to pass thru a synchronization.
if ( peMain.isStartingUp() ) {
waitOnAccept(sc.socket());
} else {
waitForServiceStartUp(sc.socket());
}
|
static void | waitOnAccept(java.net.Socket s)
if ( peMain.isStartingUp() ) {
int localPort = s.getLocalPort();
if ( !exists(localPort) ) { // Check if port is managed
return;
}
// If client is in this JVM, dont wait
synchronized ( peMain ) {
while ( peMain.isStartingUp() && ! hasClientSocketLocalPorts(s) ) {
if ( logger.isLoggable(Level.FINE) ) {
logger.fine("In ASSocketService.waitOnAccept for localport " + localPort);
}
try {
peMain.wait();
} catch ( Exception ex ) {}
}
}
}
waitForServiceStartUp(s);
|
public static void | waitOnClientConnection(int port)If a client connects from within appserver and
that triggers the service startup, that
client should wait until service startup
completes before being accepted by server.
This method should be called, if and only if the
connection is first ever connection to the server.
ASSocketService ss = ASSocketService.get(port);
if (ss != null) {
ss._waitOnClientConnection();
}
|