/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The Activator facilitates remote object activation. A "faulting"
* remote reference calls the activator's <code>activate</code> method
* to obtain a "live" reference to a activatable remote object. Upon
* receiving a request for activation, the activator looks up the
* activation descriptor for the activation identifier, id, determines
* the group in which the object should be activated and invokes the
* activate method on the object's activation group (described by the
* remote interface <code>ActivationInstantiator</code>). The
* activator initiates the execution of activation groups as
* necessary. For example, if an activation group for a specific group
* identifier is not already executing, the activator will spawn a
* child process for the activation group. <p>
*
* The activator is responsible for monitoring and detecting when
* activation groups fail so that it can remove stale remote references
* from its internal tables. <p>
*
* @author Ann Wollrath
* @since 1.2
*/
/** indicate compatibility with JDK 1.2 version of class */
/** exec policy object */
private static boolean debugExec;
/** maps activation id to its respective group id */
new ConcurrentHashMap<>();
/** maps group id to its GroupEntry groups */
new ConcurrentHashMap<>();
/** number of simultaneous group exec's */
private transient int groupSemaphore;
/** counter for numbering groups */
private transient int groupCounter;
/** reliable log to hold descriptor table */
/** number of updates since last snapshot */
private transient int numUpdates;
/** the java command */
// accessed by GroupEntry
/** timeout on wait for child process to be created or destroyed */
private static final long groupTimeout =
/** take snapshot after this many updates */
private static final int snapshotInterval =
/** timeout on wait for child process to be created */
private static final long execTimeout =
private static boolean initDone = false;
// this should be a *private* method since it is privileged
}
private transient volatile boolean shuttingDown = false;
/**
* Create an uninitialized instance of Activation that can be
* populated with log data. This is only called when the initial
* snapshot is taken during the first incarnation of rmid.
*/
private Activation() {}
/**
* Recover activation state from the reliable log and initialize
* activation services.
*/
throws Exception
{
}
/**
* Initialize the Activation instantiation; start activation
* services.
*/
throws Exception
{
// initialize
numUpdates = 0;
shutdownHook = new ShutdownHook();
groupCounter = 0;
// Use array size of 0, since the value from calling size()
// may be out of date by the time toArray() is called.
synchronized (startupLock = new Object()) {
// all the remote methods briefly synchronize on startupLock
// (via checkShutdown) to make sure they don't happen in the
// middle of this block. This block must not cause any such
// incoming remote calls to happen, or deadlock would result!
synchronized (initLock) {
initDone = true;
}
}
}
startupLock = null;
// restart services
try {
} catch (UnknownGroupException e) {
getTextResource("rmid.restart.group.warning"));
e.printStackTrace();
}
}
}
/**
* Previous versions used HashMap instead of ConcurrentHashMap.
* Replace any HashMaps found during deserialization with
* ConcurrentHashMaps.
*/
throws IOException, ClassNotFoundException
{
if (! (groupTable instanceof ConcurrentHashMap)) {
}
if (! (idTable instanceof ConcurrentHashMap)) {
}
}
throws RemoteException
{
this.systemStub = systemStub;
}
/**
* Returns the activation system stub if the specified name
* matches the activation system's class name, otherwise
* returns the result of invoking super.lookup with the specified
* name.
*/
throws RemoteException, NotBoundException
{
return systemStub;
} else {
}
}
if (length > 0) {
}
return list2;
}
{
throw new AccessException(
"binding ActivationSystem is disallowed");
} else {
}
}
{
throw new AccessException(
"unbinding ActivationSystem is disallowed");
} else {
}
}
throws RemoteException, AccessException
{
throw new AccessException(
"binding ActivationSystem is disallowed");
} else {
}
}
}
// Because ActivatorImpl has a fixed ObjID, it can be
// called by clients holding stale remote references. Each of
// its remote methods, then, must check startupLock (calling
// checkShutdown() is easiest).
/**
* Construct a new Activator on a specified port.
*/
throws RemoteException
{
/* Server ref must be created and assigned before remote object
* 'this' can be exported.
*/
}
boolean force)
{
}
}
implements ActivationMonitor
{
throws RemoteException
{
}
{
try {
} catch (ActivationException e) {
return;
}
}
{
try {
} catch (ActivationException e) {
return;
}
}
long incarnation)
throws UnknownGroupException, RemoteException
{
try {
} catch (ActivationException e) {
return;
}
}
}
class ActivationSystemImpl
extends RemoteServer
implements ActivationSystem
{
// Because ActivationSystemImpl has a fixed ObjID, it can be
// called by clients holding stale remote references. Each of
// its remote methods, then, must check startupLock (calling
// checkShutdown() is easiest).
throws RemoteException
{
/* Server ref must be created and assigned before remote object
* 'this' can be exported.
*/
}
{
return id;
}
{
}
throws ActivationException, RemoteException
{
// table insertion must take place before log update
return id;
}
long incarnation)
{
return monitor;
}
{
// remove entry before unregister so state is updated before
// logged
}
{
throw new ActivationException(
"ActivationDesc contains wrong group");
}
}
{
"ActivationSystem.setActivationGroupDesc");
}
{
}
{
("ActivationSystem.getActivationGroupDesc");
}
/**
* Shutdown the activation system. Destroys all groups spawned by
* the activation daemon and exits the activation daemon.
*/
synchronized (lock) {
// nothing
}
}
synchronized (Activation.this) {
if (!shuttingDown) {
shuttingDown = true;
}
}
}
}
// if the startup critical section is running, wait until it
synchronized (lock) {
// nothing
}
}
if (shuttingDown == true) {
throw new ActivationException(
"activation system shutting down");
}
}
for (;;) {
try {
break;
} else {
}
} catch (Exception e) {
continue;
}
}
}
/**
* Thread to shutdown rmid.
*/
Shutdown() {
super("rmid Shutdown");
}
public void run() {
try {
/*
* Unexport activation system services
*/
// destroy all child processes (groups)
}
/*
* Unexport monitor safely since all processes are destroyed.
*/
/*
* Close log file, fix for 4243264: rmid shutdown thread
* interferes with remote calls in progress. Make sure
* the log file is only closed when it is impossible for
* its closure to interfere with any pending remote calls.
* We close the log when all objects in the rmid VM are
* unexported.
*/
try {
synchronized (log) {
}
} catch (IOException e) {
}
} finally {
/*
* Now exit... A System.exit should only be done if
* the RMI activation system daemon was started up
* by the main method below (in which should always
* be the case since the Activation contructor is private).
*/
}
}
}
/** Thread to destroy children in the event of abnormal termination. */
ShutdownHook() {
super("rmid ShutdownHook");
}
public void run() {
synchronized (Activation.this) {
shuttingDown = true;
}
// destroy all child processes (groups) quickly
}
}
}
/**
* Returns the groupID for a given id of an object in the group.
* Throws UnknownObjectException if the object is not registered.
*/
throws UnknownObjectException
{
return groupID;
}
}
/**
* Returns the group entry for the group id, optionally removing it.
* Throws UnknownGroupException if the group is not registered.
*/
throws UnknownGroupException
{
if (rm) {
} else {
}
return entry;
}
}
throw new UnknownGroupException("group unknown");
}
/**
* Returns the group entry for the group id. Throws
* UnknownGroupException if the group is not registered.
*/
throws UnknownGroupException
{
return getGroupEntry(id, false);
}
/**
* Removes and returns the group entry for the group id. Throws
* UnknownGroupException if the group is not registered.
*/
throws UnknownGroupException
{
return getGroupEntry(id, true);
}
/**
* Returns the group entry for the object's id. Throws
* UnknownObjectException if the object is not registered or the
* object's group is not registered.
*/
throws UnknownObjectException
{
return entry;
}
throw new UnknownObjectException("object's group removed");
}
/**
* Container for group information: group's descriptor, group's
* instantiator, flag to indicate pending group creation, and
* table of the group's actived objects.
*
* WARNING: GroupEntry objects should not be written into log file
* updates. GroupEntrys are inner classes of Activation and they
* can not be serialized independent of this class. If the
* complete Activation system is written out as a log update, the
* point of having updates is nullified.
*/
/** indicate compatibility with JDK 1.2 version of class */
transient boolean removed = false;
}
void restartServices() {
synchronized (this) {
if (restartSet.isEmpty()) {
return;
}
/*
* Clone the restartSet so the set does not have to be locked
* during iteration. Locking the restartSet could cause
* deadlock if an object we are restarting caused another
* object in this group to be activated.
*/
}
try {
} catch (Exception e) {
if (shuttingDown) {
return;
}
getTextResource("rmid.restart.service.warning"));
e.printStackTrace();
}
}
}
long instIncarnation)
{
if (incarnation != instIncarnation) {
throw new ActivationException("invalid incarnation");
}
return;
} else {
throw new ActivationException("group already active");
}
}
throw new ActivationException("group not being created");
}
notifyAll();
}
if (removed) {
throw new UnknownGroupException("group removed");
}
}
throws UnknownObjectException
{
if (removed) {
throw new UnknownObjectException("object's group removed");
}
throw new UnknownObjectException("object unknown");
}
return objEntry;
}
boolean addRecord)
{
checkRemoved();
if (desc.getRestartMode() == true) {
}
// table insertion must take place before log update
if (addRecord) {
}
}
{
}
// table removal must take place before log update
if (addRecord) {
}
}
{
checkRemoved();
removed = true;
{
}
restartSet.clear();
reset();
childGone();
// removal should be recorded before log update
if (addRecord) {
}
}
boolean addRecord)
{
if (desc.getRestartMode() == true) {
} else {
}
// restart information should be recorded before log update
if (addRecord) {
}
return oldDesc;
}
{
}
boolean addRecord)
{
checkRemoved();
// state update should occur before log update
if (addRecord) {
}
return oldDesc;
}
throws UnknownGroupException
{
checkRemoved();
if (this.incarnation != incarnation) {
throw new UnknownGroupException("invalid incarnation");
}
reset();
if (failure) {
terminate();
}
}
throws UnknownObjectException
{
}
throws UnknownObjectException
{
}
private synchronized void reset() {
objectEntry.reset();
}
}
private void childGone() {
notifyAll();
}
}
private void terminate() {
notifyAll();
}
}
/*
* Fallthrough from TERMINATE to TERMINATING
* is intentional
*/
@SuppressWarnings("fallthrough")
private void await() {
while (true) {
switch (status) {
case NORMAL:
return;
case TERMINATE:
terminate();
case TERMINATING:
try {
} catch (IllegalThreadStateException e) {
try {
} catch (InterruptedException ee) {
}
continue;
}
// REMIND: print message that group did not terminate?
}
childGone();
return;
case CREATING:
try {
wait();
} catch (InterruptedException e) {
}
}
}
}
// no synchronization to avoid delay wrt getInstantiator
void shutdownFast() {
if (p != null) {
p.destroy();
}
}
synchronized void shutdown() {
reset();
terminate();
await();
}
boolean force)
throws ActivationException
{
/*
* Attempt to activate object and reattempt (several times)
* if activation fails due to communication problems.
*/
long currentIncarnation;
// look up object to activate
synchronized (this) {
// if not forcing activation, return cached stub
}
}
boolean groupInactive = false;
boolean failure = false;
// activate object
try {
} catch (NoSuchObjectException e) {
groupInactive = true;
detail = e;
} catch (ConnectException e) {
groupInactive = true;
failure = true;
detail = e;
} catch (ConnectIOException e) {
groupInactive = true;
failure = true;
detail = e;
} catch (InactiveGroupException e) {
groupInactive = true;
detail = e;
} catch (RemoteException e) {
// REMIND: wait some here before continuing?
detail = e;
}
}
if (groupInactive) {
// group has failed or is inactive; mark inactive
try {
getTextResource("rmid.group.inactive"),
} catch (UnknownGroupException e) {
// not a problem
}
}
}
/**
* signal that group activation failed, nested exception
* specifies what exception occurred when the group did not
* activate
*/
throw new ActivationException("object activation failed after " +
}
/**
* Returns the instantiator for the group specified by id and
* entry. If the group is currently inactive, exec some
* bootstrap code to create the group.
*/
throws ActivationException
{
await();
return group;
}
checkRemoved();
boolean acquired = false;
try {
groupName = Pstartgroup();
acquired = true;
if (debugExec) {
int j;
}
getTextResource("rmid.exec.command"),
}
try {
++incarnation;
// handle child I/O streams before writing to child
try (MarshalOutputStream out =
}
} catch (IOException e) {
terminate();
throw new ActivationException(
"unable to create activation group", e);
}
try {
do {
return group;
}
} catch (InterruptedException e) {
}
terminate();
throw new ActivationException(
(removed ?
"activation group unregistered" :
"timeout creating child process"));
} finally {
if (acquired) {
Vstartgroup();
}
}
}
/**
* Waits for process termination and then restarts services.
*/
private boolean canInterrupt = true;
private boolean shouldQuit = false;
private boolean shouldRestart = true;
Watchdog() {
setDaemon(true);
}
public void run() {
if (shouldQuit) {
return;
}
/*
* Wait for the group to crash or exit.
*/
try {
} catch (InterruptedException exit) {
return;
}
boolean restart = false;
synchronized (GroupEntry.this) {
if (shouldQuit) {
return;
}
canInterrupt = false;
interrupted(); // clear interrupt bit
/*
* Since the group crashed, we should
* reset the entry before activating objects
*/
if (groupIncarnation == incarnation) {
reset();
childGone();
}
}
/*
* Activate those objects that require restarting
* after a crash.
*/
if (restart) {
}
}
/**
* Marks this thread as one that is no longer needed.
* If the thread is in a state in which it can be interrupted,
* then the thread is interrupted.
*/
void dispose() {
shouldQuit = true;
if (canInterrupt) {
interrupt();
}
}
/**
* Marks this thread as no longer needing to restart objects.
*/
void noRestart() {
shouldRestart = false;
}
}
}
// argv is the literal command to exec
? cmdenv.getCommandPath()
: command[0]);
// Group-specific command options
}
// Properties become -D parameters
p.hasMoreElements();)
{
/* Note on quoting: it would be wrong
* here, since argv will be passed to
* Runtime.exec, which should not parse
* arguments or split on whitespace.
*/
}
}
/* Finally, rmid-global command options (e.g. -C options)
* and the classname
*/
}
return realArgv;
}
throws SecurityException, ActivationException
{
/*
* Check exec command using execPolicy object
*/
if (execPolicyMethod != null) {
}
try {
} catch (InvocationTargetException e) {
if (targetException instanceof SecurityException) {
throw (SecurityException) targetException;
} else {
throw new ActivationException(
e);
}
} catch (Exception e) {
throw new ActivationException(
}
}
}
/** descriptor for object */
/** the stub (if active) */
volatile transient boolean removed = false;
}
synchronized MarshalledObject<? extends Remote>
boolean force,
throws RemoteException, ActivationException
{
if (removed) {
throw new UnknownObjectException("object removed");
return nstub;
}
/*
* stub could be set to null by a group reset, so return
* the newstub here to prevent returning null.
*/
return nstub;
}
void reset() {
}
}
/**
* Add a record to the activation log. If the number of updates
* passes a predetermined threshold, record a snapshot.
*/
synchronized (log) {
try {
} catch (Exception e) {
e.printStackTrace();
}
if (++numUpdates < snapshotInterval) {
return;
}
try {
numUpdates = 0;
} catch (Exception e) {
getTextResource("rmid.log.snapshot.warning"));
e.printStackTrace();
try {
// shutdown activation system because snapshot failed
} catch (RemoteException ignore) {
// can't happen
}
// warn the client of the original update problem
throw new ActivationException("log snapshot failed", e);
}
}
}
/**
* Handler for the log that knows how to take the initial snapshot
* and apply an update (a LogRecord) to the current state.
*/
ActLogHandler() {
}
{
/**
* Return an empty Activation object. Log will update
* this object with recovered state.
*/
return new Activation();
}
throws Exception
{
}
}
/**
* Abstract class for all log records. The subclass contains
* specific update information and implements the apply method
* that applys the update information contained in the record
* to the current state.
*/
/** indicate compatibility with JDK 1.2 version of class */
}
/**
* Log record for registering an object.
*/
/** indicate compatibility with JDK 1.2 version of class */
}
try {
getTextResource("rmid.log.recover.warning"),
"LogRegisterObject"));
}
return state;
}
}
/**
* Log record for unregistering an object.
*/
/** indicate compatibility with JDK 1.2 version of class */
}
try {
unregisterObject(id, false);
getTextResource("rmid.log.recover.warning"),
"LogUnregisterObject"));
}
return state;
}
}
/**
* Log record for registering a group.
*/
/** indicate compatibility with JDK 1.2 version of class */
}
// modify state directly; cant ask a nonexistent GroupEntry
// to register itself.
return state;
}
}
/**
* Log record for udpating an activation desc
*/
/** indicate compatibility with JDK 1.2 version of class */
}
try {
getTextResource("rmid.log.recover.warning"),
"LogUpdateDesc"));
}
return state;
}
}
/**
* Log record for unregistering a group.
*/
/** indicate compatibility with JDK 1.2 version of class */
}
try {
getTextResource("rmid.log.recover.warning"),
"LogUpdateGroupDesc"));
}
return state;
}
}
/**
* Log record for unregistering a group.
*/
/** indicate compatibility with JDK 1.2 version of class */
}
try {
entry.unregisterGroup(false);
getTextResource("rmid.log.recover.warning"),
"LogUnregisterGroup"));
}
return state;
}
}
/**
* Log record for an active group incarnation
*/
/** indicate compatibility with JDK 1.2 version of class */
private long inc;
}
try {
getTextResource("rmid.log.recover.warning"),
"LogGroupIncarnation"));
}
return state;
}
}
/**
* Initialize command to exec a default group.
*/
try {
} catch (Exception e) {
getTextResource("rmid.unfound.java.home.property"));
}
return null;
}
});
}
"rmid"));
}
/**
* The default policy for checking a command before it is executed
* makes sure the appropriate com.sun.rmi.rmid.ExecPermission and
* set of com.sun.rmi.rmid.ExecOptionPermissions have been granted.
*/
public static class DefaultExecPolicy {
throws SecurityException
{
/*
* Check properties overrides.
*/
while (p.hasMoreElements()) {
try {
new ExecOptionPermission(option));
} catch (AccessControlException e) {
} else {
throw e;
}
}
}
}
/*
* Check group class name (allow nothing but the default),
* code location (must be null), and data (must be null).
*/
if ((groupClassName != null &&
ActivationGroupImpl.class.getName())) ||
{
throw new AccessControlException(
"access denied (custom group implementation not allowed)");
}
/*
* If group descriptor has a command environment, check
* command and options.
*/
}
new ExecOptionPermission(option));
}
}
}
}
/**
* Prints warning message if installed Policy is the default Policy
* implementation and globally granted permissions do not include
* AllPermission or any ExecPermissions/ExecOptionPermissions.
*/
static void checkConfiguration() {
}
});
if (!(policy instanceof PolicyFile)) {
return;
}
e.hasMoreElements();)
{
Permission p = e.nextElement();
if (p instanceof AllPermission ||
p instanceof ExecPermission ||
p instanceof ExecOptionPermission)
{
return;
}
}
}
/*
* The approach used here is taken from the similar method
* getLoaderAccessControlContext() in the class
* sun.rmi.server.LoaderHandler.
*/
// obtain permissions granted to all code in current policy
new PrivilegedAction<PermissionCollection>() {
public PermissionCollection run() {
if (p != null) {
return p.getPermissions(codesource);
} else {
return new Permissions();
}
}
});
return perms;
}
Permission p)
throws AccessControlException
{
throw new AccessControlException(
"access denied " + p.toString());
}
}
}
/**
* Main program to start the activation system. <br>
* The usage is as follows: rmid [-port num] [-log dir].
*/
boolean stop = false;
// Create and install the security manager if one is not installed
// already.
}
try {
/*
* If rmid has an inherited channel (meaning that it was
* launched from inetd), set the server socket factory to
* return the inherited server socket.
**/
new PrivilegedExceptionAction<Channel>() {
return System.inheritedChannel();
}
});
if (inheritedChannel != null &&
inheritedChannel instanceof ServerSocketChannel)
{
/*
* Redirect System.err output to a file.
*/
new PrivilegedExceptionAction<Void>() {
return null;
}
});
"rmid.inherited.channel.info") +
": " + inheritedChannel);
}
/*
* Parse arguments
*/
}
try {
} catch (NumberFormatException nfe) {
}
} else {
}
} else {
}
stop = true;
} else {
getTextResource("rmid.syntax.illegal.option"),
args[i]));
}
}
} else {
log = "log";
}
}
new GetBooleanAction("sun.rmi.server.activation.debugExec"));
/**
* Determine class name for activation exec policy (if any).
*/
if (execPolicyClassName == null) {
if (!stop) {
}
execPolicyClassName = "default";
}
/**
* Initialize method for activation exec policy.
*/
{
}
try {
ActivationGroupDesc.class,
String[].class);
} catch (Exception e) {
if (debugExec) {
getTextResource("rmid.exec.policy.exception"));
e.printStackTrace();
}
}
}
if (stop == true) {
return null;
}
});
}
/*
* Fix for 4173960: Create and initialize activation using
* a static method, startActivation, which will build the
* Activation state in two ways: if when rmid is run, no
* log file is found, the ActLogHandler.recover(...)
* method will create a new Activation instance.
* Alternatively, if a logfile is available, a serialized
* instance of activation will be read from the log's
* snapshot file. Log updates will be applied to this
* Activation object until rmid's state has been fully
* recovered. In either case, only one instance of
* Activation is created.
*/
// prevent activator from exiting
while (true) {
try {
} catch (InterruptedException e) {
}
}
} catch (Exception e) {
getTextResource("rmid.unexpected.exception"), e));
e.printStackTrace();
}
}
/**
* Retrieves text resources from the locale-specific properties file.
*/
try {
"sun.rmi.server.resources.rmid");
} catch (MissingResourceException mre) {
}
// throwing an Error is a bit extreme, methinks
}
}
try {
} catch (MissingResourceException mre) {
}
} else {
return val;
}
}
@SuppressWarnings("deprecation")
}
/*
* Dijkstra semaphore operations to limit the number of subprocesses
* rmid attempts to make at once.
*/
/**
* Acquire the group semaphore and return a group name. Each
* Pstartgroup must be followed by a Vstartgroup. The calling thread
* will wait until there are fewer than <code>N</code> other threads
* holding the group semaphore. The calling thread will then acquire
* the semaphore and return.
*/
while (true) {
// Wait until positive, then decrement.
if (groupSemaphore > 0) {
return "Group-" + groupCounter++;
}
try {
wait();
} catch (InterruptedException e) {
}
}
}
/**
* Release the group semaphore. Every P operation must be
* followed by a V operation. This may cause another thread to
* wake up and return from its P operation.
*/
private synchronized void Vstartgroup() {
// Increment and notify a waiter (not necessarily FIFO).
notifyAll();
}
/**
* A server socket factory to use when rmid is launched via 'inetd'
* with 'wait' status. This socket factory's 'createServerSocket'
* method returns the server socket specified during construction that
* is specialized to delay accepting requests until the
* 'initDone' flag is 'true'. The server socket supplied to
* the constructor should be the server socket obtained from the
* ServerSocketChannel returned from the 'System.inheritedChannel'
* method.
**/
private static class ActivationServerSocketFactory
implements RMIServerSocketFactory
{
/**
* Constructs an 'ActivationServerSocketFactory' with the specified
* 'serverSocket'.
**/
this.serverSocket = serverSocket;
}
/**
* Returns the server socket specified during construction wrapped
* in a 'DelayedAcceptServerSocket'.
**/
throws IOException
{
return new DelayedAcceptServerSocket(serverSocket);
}
}
/**
* A server socket that delegates all public methods to the underlying
* server socket specified at construction. The accept method is
* overridden to delay calling accept on the underlying server socket
* until the 'initDone' flag is 'true'.
**/
throws IOException
{
this.serverSocket = serverSocket;
}
}
throws IOException
{
}
return AccessController.doPrivileged(
new PrivilegedAction<InetAddress>() {
public InetAddress run() {
return serverSocket.getInetAddress();
}
});
}
public int getLocalPort() {
return serverSocket.getLocalPort();
}
return AccessController.doPrivileged(
new PrivilegedAction<SocketAddress>() {
public SocketAddress run() {
return serverSocket.getLocalSocketAddress();
}
});
}
/**
* Delays calling accept on the underlying server socket until the
* remote service is bound in the registry.
**/
synchronized (initLock) {
try {
while (!initDone) {
}
} catch (InterruptedException ignore) {
throw new AssertionError(ignore);
}
}
return serverSocket.accept();
}
}
return serverSocket.getChannel();
}
public boolean isBound() {
return serverSocket.isBound();
}
public boolean isClosed() {
return serverSocket.isClosed();
}
throws SocketException
{
}
return serverSocket.getSoTimeout();
}
}
return serverSocket.getReuseAddress();
}
return serverSocket.toString();
}
throws SocketException
{
}
public int getReceiveBufferSize()
throws SocketException
{
return serverSocket.getReceiveBufferSize();
}
}
}
/**
* PipeWriter plugs together two pairs of input and output streams by
* providing readers for input streams and writing through to
* appropriate output streams. Both output streams are annotated on a
* per-line basis.
*
* @author Laird Dornin, much code borrowed from Peter Jones, Ken
* Arnold and Ann Wollrath.
*/
/** stream used for buffering lines */
/** count since last separator */
private int cLast;
/** current chunk of input being compared to lineSeparator.*/
private byte[] currSep;
private static int lineSeparatorLength;
static {
new GetPropertyAction("line.separator"));
}
/**
* Create a new PipeWriter object. All methods of PipeWriter,
* except plugTogetherPair, are only accesible to PipeWriter
* itself. Synchronization is unnecessary on functions that will
* only be used internally in PipeWriter.
*
* @param in input stream from which pipe input flows
* @param out output stream to which log messages will be sent
* @param dest String which tags output stream as 'out' or 'err'
* @param nExecs number of execed processes, Activation groups.
*/
private PipeWriter
bufOut = new ByteArrayOutputStream();
currSep = new byte[lineSeparatorLength];
execString = ":ExecGroup-" +
}
/**
* Create a thread to listen and read from input stream, in. buffer
* the data that is read until a marker which equals lineSeparator
* is read. Once such a string has been discovered; write out an
* annotation string followed by the buffered data and a line
* separator.
*/
public void run() {
byte[] buf = new byte[256];
int count;
try {
/* read bytes till there are no more. */
}
/* flush internal buffer... may not have ended on a line
* separator, we also need a last annotation if
* something was left.
*/
// to make output nicer
}
} catch (IOException e) {
}
}
/**
* Write a subarray of bytes. Pass each through write byte method.
*/
if (len < 0) {
throw new ArrayIndexOutOfBoundsException(len);
}
for (int i = 0; i < len; ++ i) {
}
}
/**
* Write a byte of data to the stream. If we have not matched a
* line separator string, then the byte is appended to the internal
* buffer. If we have matched a line separator, then the currently
* buffered line is sent to the output writer with a prepended
* annotation string.
*/
int i = 0;
/* shift current to the left */
}
currSep[i-1] = b;
/* enough characters for a separator? */
cLast = 0;
/* write prefix through to underlying byte stream */
if (out.checkError()) {
throw new IOException
("PipeWriter: IO Exception when"+
" writing to output stream.");
}
} else {
cLast++;
}
}
/**
* Create an annotation string to be printed out after
* a new line and end of stream.
*/
/* construct prefix for log messages:
*/
/* ... print pair # ... */
(execString));
}
/**
* Allow plugging together two pipes at a time, to associate
* output from an execed process. This is the only publicly
* accessible method of this object; this helps ensure that
* synchronization will not be an issue in the annotation
* process.
*
* @param in input stream from which pipe input comes
* @param out output stream to which log messages will be sent
* @param in1 input stream from which pipe input comes
* @param out1 output stream to which log messages will be sent
*/
OutputStream out1) {
int nExecs = getNumExec();
/* start RMI threads to read output from child process */
"out", true));
"err", true));
}
private static synchronized int getNumExec() {
return numExecs++;
}
}