From: <cr...@us...> - 2008-10-02 13:46:37
|
Revision: 4596 http://jnode.svn.sourceforge.net/jnode/?rev=4596&view=rev Author: crawley Date: 2008-10-02 13:42:14 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Moved classes in org.jnode.vm.isolate.link to org.jnode.vm.isolate. This will allow us to tighten access on various internal classes / methods Modified Paths: -------------- trunk/core/descriptors/org.jnode.vm.core.xml trunk/core/src/classpath/ext/javax/isolate/Link.java trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandLauncher.java trunk/shell/src/shell/org/jnode/shell/isolate/IsolateCommandThreadImpl.java Added Paths: ----------- trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/VmLink.java Removed Paths: ------------- trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/link/LinkImpl.java trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageFactory.java trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java Modified: trunk/core/descriptors/org.jnode.vm.core.xml =================================================================== --- trunk/core/descriptors/org.jnode.vm.core.xml 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/descriptors/org.jnode.vm.core.xml 2008-10-02 13:42:14 UTC (rev 4596) @@ -25,7 +25,6 @@ <export name="org.jnode.vm.classmgr.*"/> <export name="org.jnode.vm.compiler.*"/> <export name="org.jnode.vm.isolate.*"/> - <export name="org.jnode.vm.isolate.link.*"/> <export name="org.jnode.vm.memmgr.*"/> <export name="org.jnode.vm.performance.*"/> <export name="org.jnode.vm.scheduler.*"/> Modified: trunk/core/src/classpath/ext/javax/isolate/Link.java =================================================================== --- trunk/core/src/classpath/ext/javax/isolate/Link.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/classpath/ext/javax/isolate/Link.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -24,7 +24,7 @@ import java.io.IOException; import java.io.InterruptedIOException; -import org.jnode.vm.isolate.link.VmLink; +import org.jnode.vm.isolate.VmLink; /** * @author Ewout Prangsma (ep...@us...) Modified: trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java =================================================================== --- trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/classpath/ext/javax/isolate/LinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -24,7 +24,7 @@ import java.net.ServerSocket; import java.net.Socket; -import org.jnode.vm.isolate.link.LinkMessageFactory; +import org.jnode.vm.isolate.LinkMessageFactory; /** * @author Ewout Prangsma (ep...@us...) Added: trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/DataLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,60 @@ +/* + * $Id: DataLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $ + */ +package org.jnode.vm.isolate; + + +final class DataLinkMessage extends LinkMessageImpl { + + private final byte[] bytes; + + private final int offset; + + private final int length; + + public DataLinkMessage(byte[] bytes, int offset, int length) { + this.bytes = bytes; + this.offset = offset; + this.length = length; + } + + /** + * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() + */ + @Override + LinkMessageImpl cloneMessage() { + final byte[] data = new byte[length]; + System.arraycopy(bytes, offset, data, 0, length); + return new DataLinkMessage(data, 0, length); + } + + /** + * @see javax.isolate.LinkMessage#containsData() + */ + @Override + public boolean containsData() { + return true; + } + + /** + * @see javax.isolate.LinkMessage#extract() + */ + @Override + public Object extract() { + return extractData(); + } + + /** + * @see javax.isolate.LinkMessage#extractData() + */ + @Override + public byte[] extractData() { + if ((offset == 0) && (length == bytes.length)) { + return bytes; + } else { + byte[] data = new byte[length]; + System.arraycopy(bytes, offset, data, 0, length); + return data; + } + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/IsolateLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,54 @@ +/* + * $Id: IsolateLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $ + */ +package org.jnode.vm.isolate; + +import javax.isolate.Isolate; + + + +final class IsolateLinkMessage extends LinkMessageImpl { + + private final VmIsolate value; + + /** + * Message constructor + * + * @param value + */ + IsolateLinkMessage(VmIsolate isolate) { + this.value = isolate; + } + + /** + * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() + */ + @Override + LinkMessageImpl cloneMessage() { + return new IsolateLinkMessage(value); + } + + /** + * @see javax.isolate.LinkMessage#extract() + */ + @Override + public Object extract() { + return extractIsolate(); + } + + /** + * @see javax.isolate.LinkMessage#containsIsolate() + */ + @Override + public boolean containsIsolate() { + return true; + } + + /** + * @see javax.isolate.LinkMessage#extractIsolate() + */ + @Override + public Isolate extractIsolate() { + return value.getIsolate(); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/LinkImpl.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,98 @@ +/* + * $Id: DataLinkImpl.java 4552 2008-09-11 11:38:42Z crawley $ + */ +package org.jnode.vm.isolate; + +import java.io.IOException; +import java.io.InterruptedIOException; + +import javax.isolate.ClosedLinkException; +import javax.isolate.Isolate; +import javax.isolate.Link; +import javax.isolate.LinkMessage; + +final class LinkImpl extends Link { + + private final VmLink vmLink; + + /** + * Constructor + * + * @param vmLink + */ + LinkImpl(VmLink vmLink) { + this.vmLink = vmLink; + } + + final VmLink getImpl() { + return vmLink; + } + + /** + * @see javax.isolate.Link#close() + */ + @Override + public void close() { + vmLink.close(); + } + + /** + * @see javax.isolate.Link#Equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (other instanceof LinkImpl) { + return (((LinkImpl) other).vmLink == this.vmLink); + } + return false; + } + + /** + * @see javax.isolate.Link#getReceiver() + */ + @Override + public Isolate getReceiver() { + return vmLink.getReceiver().getIsolate(); + } + + /** + * @see javax.isolate.Link#getSender() + */ + @Override + public Isolate getSender() { + return vmLink.getSender().getIsolate(); + } + + /** + * @see javax.isolate.Link#isOpen() + */ + @Override + public boolean isOpen() { + return vmLink.isOpen(); + } + + /** + * @see javax.isolate.Link#receive() + */ + @Override + public LinkMessage receive() + throws ClosedLinkException, IllegalStateException, InterruptedIOException, IOException { + return vmLink.receive(); + } + + /** + * @see javax.isolate.Link#send(javax.isolate.LinkMessage) + */ + @Override + public void send(LinkMessage message) throws ClosedLinkException, InterruptedIOException, IOException { + vmLink.send(message); + } + + /** + * @see javax.isolate.Link#toString() + */ + @Override + public String toString() { + return vmLink.toString(); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/LinkLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,53 @@ +/* + * $Id: LinkLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $ + */ +package org.jnode.vm.isolate; + +import javax.isolate.Link; + + +final class LinkLinkMessage extends LinkMessageImpl { + + private final VmLink value; + + /** + * Message constructor + * + * @param value + */ + LinkLinkMessage(VmLink link) { + this.value = link; + } + + /** + * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() + */ + @Override + LinkMessageImpl cloneMessage() { + return new LinkLinkMessage(value); + } + + /** + * @see javax.isolate.LinkMessage#extract() + */ + @Override + public Object extract() { + return extractLink(); + } + + /** + * @see javax.isolate.LinkMessage#containsLink() + */ + @Override + public boolean containsLink() { + return true; + } + + /** + * @see javax.isolate.LinkMessage#extractLink() + */ + @Override + public Link extractLink() { + return value.asLink(); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/LinkMessageFactory.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,83 @@ +/* + * $Id: LinkMessageFactory.java 4592 2008-09-30 12:00:11Z crawley $ + */ +package org.jnode.vm.isolate; + +import java.net.ServerSocket; +import java.net.Socket; + +import javax.isolate.Link; +import javax.isolate.LinkMessage; + + +public final class LinkMessageFactory { + + /** + * Create a LinkMessage containing the given link messages. + * + * @param messages + * @return + */ + public static LinkMessage newCompositeMessage(LinkMessage... messages) { + throw new UnsupportedOperationException(); + } + + /** + * Create a LinkMessage containing the given data. + * + * @param bytes + * @return + */ + public static LinkMessage newDataMessage(byte[] bytes, + int offset, + int length) { + return new DataLinkMessage(bytes, offset, length); + } + + /** + * Create a LinkMessage containing the given isolate. + * + * @param isolate + * @return + */ + public static LinkMessage newIsolateMessage(VmIsolate isolate) { + throw new UnsupportedOperationException(); + } + + /** + * Create a LinkMessage containing the given link. + * + * @return + */ + public static LinkMessage newLinkMessage(Link link) { + return new LinkLinkMessage(((LinkImpl) link).getImpl()); + } + + /** + * Create a LinkMessage containing the given server socket. + * + * @return + */ + public static LinkMessage newServerSocketMessage(ServerSocket socket) { + throw new UnsupportedOperationException(); + } + + /** + * Create a LinkMessage containing the given socket. + * + * @return + */ + public static LinkMessage newSocketMessage(Socket socket) { + throw new UnsupportedOperationException(); + } + + /** + * Create a LinkMessage containing the given string. + * + * @param string + * @return + */ + public static LinkMessage newStringMessage(String string) { + return new StringLinkMessage(string); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/LinkMessageImpl.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,44 @@ +/* + * $Id: LinkMessageImpl.java 4595 2008-10-02 13:24:26Z crawley $ + */ +package org.jnode.vm.isolate; + +import javax.isolate.LinkMessage; + +/** + * Base class for all types of LinkMessage implementation classes. + * + * @author Ewout Prangsma (ep...@us...) + */ +abstract class LinkMessageImpl extends LinkMessage { + + private boolean received = false; + + /** + * Close this message in the current isolate. + * + * @return + */ + abstract LinkMessageImpl cloneMessage(); + + /** + * Block the current thread, until this message has its received flag set. + */ + final void waitUntilReceived() throws InterruptedException { + if (!received) { + synchronized (this) { + while (!received) { + wait(); + } + } + } + } + + /** + * Mark this message as received and notify all waiting threads. + */ + final synchronized void notifyReceived() { + this.received = true; + notifyAll(); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/ObjectLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,50 @@ +/* + * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library 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 Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.jnode.vm.isolate; + +/** + * This message type passes an object by reference. This is probably a bad idea + * because it 'breaks' the isolation of isolates. Use sparingly if at all. + * + * @author cr...@jn... + */ +public class ObjectLinkMessage extends LinkMessageImpl { + + private final Object obj; + + private ObjectLinkMessage(Object cr) { + this.obj = cr; + } + + public static ObjectLinkMessage newMessage (Object obj) { + return new ObjectLinkMessage(obj); + } + + @Override + public Object extract() { + return obj; + } + + @Override + LinkMessageImpl cloneMessage() { + return new ObjectLinkMessage(obj); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/StatusLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,90 @@ +/* + * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library 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 Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.jnode.vm.isolate; + +import javax.isolate.IsolateStatus; + +/** + * This class is use to transport status isolate information + * @author cr...@jn... + */ +public final class StatusLinkMessage extends LinkMessageImpl { + + private final String state; + private final String exitReason; + private final int exitCode; + + /** + * Internal message constructor used by cloneMessage + * + * @param value + */ + private StatusLinkMessage(String state, String exitReason, int exitCode) { + this.state = state; + this.exitReason = exitReason; + this.exitCode = exitCode; + } + + /** + * Message constructor used VmIsolate + * + * @param value + */ + public StatusLinkMessage(IsolateStatus.State state, IsolateStatus.ExitReason exitReason, + int exitCode) { + this(state.toString(), exitReason.toString(), exitCode); + } + + /** + * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() + */ + @Override + LinkMessageImpl cloneMessage() { + return new StatusLinkMessage(state, exitReason, exitCode); + } + + /** + * @see javax.isolate.LinkMessage#extract() + */ + @Override + public Object extract() { + return extractStatus(); + } + + /** + * @see javax.isolate.LinkMessage#containsString() + */ + @Override + public boolean containsStatus() { + return true; + } + + /** + * @see javax.isolate.LinkMessage#extractString() + */ + @Override + public IsolateStatus extractStatus() { + return new IsolateStatus( + IsolateStatus.State.valueOf(state), + IsolateStatus.ExitReason.valueOf(exitReason), + exitCode); + } +} Added: trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/StringLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,51 @@ +/* + * $Id: StringLinkMessage.java 4595 2008-10-02 13:24:26Z crawley $ + */ +package org.jnode.vm.isolate; + + +final class StringLinkMessage extends LinkMessageImpl { + + private final String value; + + /** + * Message constructor + * + * @param value + */ + StringLinkMessage(String value) { + this.value = value; + } + + /** + * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() + */ + @Override + LinkMessageImpl cloneMessage() { + return new StringLinkMessage(new String(value)); + } + + /** + * @see javax.isolate.LinkMessage#extract() + */ + @Override + public Object extract() { + return extractString(); + } + + /** + * @see javax.isolate.LinkMessage#containsString() + */ + @Override + public boolean containsString() { + return true; + } + + /** + * @see javax.isolate.LinkMessage#extractString() + */ + @Override + public String extractString() { + return value; + } +} Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -56,8 +56,6 @@ import org.jnode.vm.annotation.SharedStatics; import org.jnode.vm.classmgr.VmIsolatedStatics; import org.jnode.vm.classmgr.VmType; -import org.jnode.vm.isolate.link.StatusLinkMessage; -import org.jnode.vm.isolate.link.VmLink; /** * VM specific implementation of the Isolate class. Added: trunk/core/src/core/org/jnode/vm/isolate/VmLink.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/VmLink.java (rev 0) +++ trunk/core/src/core/org/jnode/vm/isolate/VmLink.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -0,0 +1,286 @@ +/* + * $Id: VmDataLink.java 4552 2008-09-11 11:38:42Z crawley $ + */ +package org.jnode.vm.isolate; + +import java.io.IOException; +import java.io.InterruptedIOException; +import java.util.LinkedList; +import java.util.Queue; + +import javax.isolate.ClosedLinkException; +import javax.isolate.Link; +import javax.isolate.LinkMessage; + + +/** + * Shared implementation of javax.isolate.Link + * + * @author Ewout Prangsma (ep...@us...) + */ +public final class VmLink { + + private final VmIsolateLocal<LinkImpl> linkHolder = new VmIsolateLocal<LinkImpl>(); + + private final Queue<LinkMessageImpl> messages = new LinkedList<LinkMessageImpl>(); + + private boolean closed = false; + + private VmIsolate sender; + + private VmIsolate receiver; + + /** + * Create a new data link between the given isolates. + * + * @param sender + * @param receiver + * @return + */ + public static Link newLink(VmIsolate sender, VmIsolate receiver) { + if (sender == receiver) { + throw new IllegalArgumentException("sender == receiver"); + } + VmLink vmLink = new VmLink(sender, receiver); + return vmLink.asLink(); + } + + public static VmLink fromLink(Link link) { + return ((LinkImpl) link).getImpl(); + } + + /** + * @param sender + * @param receiver + */ + VmLink(VmIsolate sender, VmIsolate receiver) { + this.sender = sender; + this.receiver = receiver; + } + + /** + * Gets this shared link as Link instance. + * + * @return + */ + public final Link asLink() { + final LinkImpl link = linkHolder.get(); + if (link == null) { + linkHolder.set(new LinkImpl(this)); + return linkHolder.get(); + } else { + return link; + } + } + + /** + * Close this link. + */ + final void close() { + if (!this.closed) { + final VmIsolate current = VmIsolate.currentIsolate(); + if ((current != receiver) && (current != sender)) { + throw new IllegalStateException( + "Only sender or receiver can close this link"); + } + this.closed = true; + synchronized (this) { + notifyAll(); + } + } + } + + /** + * Is this link currently open. + * + * @return + */ + final boolean isOpen() { + return !closed; + } + + /** + * @return the receiver + */ + final VmIsolate getReceiver() { + return receiver; + } + + /** + * @return the sender + */ + final VmIsolate getSender() { + return sender; + } + + /** + * Receives a copy of a message sent on this Link. + * <p/> + * The current thread will block in this method until a sender is available. + * When the sender and receiver rendezvous, the message will then be + * transferred. If multiple threads invoke this method on the same object, + * only one thread will receive any message at rendezvous and the other + * threads will contend for subsequent access to the rendezvous point. A + * normal return indicates that the message was received successfully. If an + * exception occured on the sender side, no rendezvous will occur, and no + * object will be transferred; the receiver will wait for the next + * successful send. If an exception occurs on the receive, the sender will + * see a successful transfer. + * <p/> + * This method never returns null. + * <p/> + * If the sending isolate becomes terminated after this method is invoked + * but before it returns, the link will be closed, a ClosedLinkException + * will be thrown, any subsequent attempts to use receive() will result in a + * ClosedLinkException, and any Isolate objects corresponding to the receive + * side of the link will reflect a terminated state. + * <p/> + * If invoked on a closed Link, this method will throw a + * ClosedLinkException. + * <p/> + * If close() is invoked on the link while a thread is blocked in receive(), + * receive() will throw a ClosedLinkException. No message will have been + * transferred in that case. + * <p/> + * If Thread.interrupt() is invoked on a thread that has not yet completed + * an invocation of this method, the results are undefined. An + * InterruptedIOException may or may not be thrown; if not, control will + * return from the method with a valid LinkMessage object. However, even if + * InterruptedIOException is thrown, rendezvous and data transfer from the + * sending isolate may have occurred. In particular, undetected message loss + * between sender and receiver may occur. + * <p/> + * If a failure occurs due to the object being transferred between isolates + * an IOException may be thrown in the receiver. For example, if a message + * containing a large buffer is sent and the receiver has insufficient heap + * memory for the buffer or if construction of a link in the receiver + * isolate fails, an IOException will be thrown. The sender will see a + * successful transfer in these cases. + * <p/> + * If the current isolate is not a receiver on this Link an + * IllegalStateException will be thrown. The receiver will not rendezvous + * with a sender in this case. + * + * @return + */ + final LinkMessage receive() throws ClosedLinkException, + IllegalStateException, InterruptedIOException, IOException { + if (VmIsolate.currentIsolate() != receiver) { + // Current isolate is not the receiver + throw new IllegalStateException(); + } + if (this.closed) { + throw new ClosedLinkException(); + } + final LinkMessageImpl message; + synchronized (this) { + while (messages.isEmpty()) { + if (this.closed) { + throw new ClosedLinkException(); + } + try { + wait(); + } catch (InterruptedException ex) { + throw new InterruptedIOException(); + } + } + message = messages.poll(); + } + message.notifyReceived(); + return message.cloneMessage(); + } + + /** + * Sends the given message on this Link. + * <p/> + * The current thread will block in this method until a receiver is + * available. When the sender and receiver rendezvous, the message will then + * be transferred. A normal return indicates that the message was + * transferred. If an exception occurs on the sender side, no rendezvous + * will occur and no object will be transferred. But if an exception occurs + * on the receive(), the sender will see a successful transfer. + * <p/> + * If the receiving isolate becomes terminated after this method is invoked + * but before it returns, the link will be closed, a ClosedLinkException + * will be thrown, any subsequent attempts to use send() will result in a + * ClosedLinkException, and any Isolate objects corresponding to the receive + * side of the link will reflect a terminated state. + * <p/> + * If invoked on a closed link, this method will throw a + * ClosedLinkException. + * <p/> + * If close() is invoked on this Link while a thread is blocked in send(), + * send() will throw a ClosedLinkException. No message will have been + * transferred in that case. + * <p/> + * If Thread.interrupt() is invoked on a thread that has not yet completed + * an invocation of this method, the results are undefined. An + * InterruptedIOException may or may not be thrown; however, even if not, + * control will return from the method. Rendezvous and data transfer to the + * receiving isolate may or may not have occurred. In particular, undetected + * message loss between sender and receiver may occur. + * <p/> + * If a failure occurs during the transfer an IOException may be thrown in + * the sender and the object will not be sent. A transfer may succeed from + * the sender's point of view, but cause an independent IOException in the + * receiver. For example, if a message containing a large buffer is sent and + * the receiver has insufficient heap memory for the buffer or if + * construction of a link in the receiver isolate fails, an IOException will + * be thrown in the receiver after the transfer completes. + * <p/> + * A ClosedLinkException will be thrown if the given LinkMessage contains a + * closed Link, Socket, or ServerSocket. No object will be transferred in + * this case. + * <p/> + * If the current isolate is not a sender on this Link, an + * UnsupportedOperationException will be thrown. No object will be sent in + * this case. + * + * @param message + * @throws ClosedLinkException + * @throws InterruptedIOException + * @throws IOException + */ + final void send(LinkMessage message) throws ClosedLinkException, + InterruptedIOException, IOException { + if (VmIsolate.currentIsolate() != sender) { + // Current isolate is not the sender for this message + throw new UnsupportedOperationException(); + } + if (this.closed) { + throw new ClosedLinkException(); + } + final LinkMessageImpl messageImpl = (LinkMessageImpl) message; + synchronized (this) { + if (this.closed) { + throw new ClosedLinkException(); + } + // Send message + messages.add(messageImpl); + notifyAll(); + } + + // Wait for the message to be picked up by the receiver + try { + messageImpl.waitUntilReceived(); + } catch (InterruptedException ex) { + throw new InterruptedIOException(); + } + } + + /** + * This method is used to send status messages. These are sent + * without blocking and are queued in the link for the receiver + * to read at its leisure. If the link is closed when this + * method is called, the message is quietly dropped. + * + * @param message the status message to be sent. + */ + public final synchronized void sendStatus(LinkMessage message) { + if (!this.closed) { + // Send message + messages.add((LinkMessageImpl) message); + notifyAll(); + } + } +} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/DataLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,60 +0,0 @@ -/* - * $Id$ - */ -package org.jnode.vm.isolate.link; - - -final class DataLinkMessage extends LinkMessageImpl { - - private final byte[] bytes; - - private final int offset; - - private final int length; - - public DataLinkMessage(byte[] bytes, int offset, int length) { - this.bytes = bytes; - this.offset = offset; - this.length = length; - } - - /** - * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() - */ - @Override - LinkMessageImpl cloneMessage() { - final byte[] data = new byte[length]; - System.arraycopy(bytes, offset, data, 0, length); - return new DataLinkMessage(data, 0, length); - } - - /** - * @see javax.isolate.LinkMessage#containsData() - */ - @Override - public boolean containsData() { - return true; - } - - /** - * @see javax.isolate.LinkMessage#extract() - */ - @Override - public Object extract() { - return extractData(); - } - - /** - * @see javax.isolate.LinkMessage#extractData() - */ - @Override - public byte[] extractData() { - if ((offset == 0) && (length == bytes.length)) { - return bytes; - } else { - byte[] data = new byte[length]; - System.arraycopy(bytes, offset, data, 0, length); - return data; - } - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/IsolateLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,55 +0,0 @@ -/* - * $Id$ - */ -package org.jnode.vm.isolate.link; - -import javax.isolate.Isolate; - -import org.jnode.vm.isolate.VmIsolate; - - -final class IsolateLinkMessage extends LinkMessageImpl { - - private final VmIsolate value; - - /** - * Message constructor - * - * @param value - */ - IsolateLinkMessage(VmIsolate isolate) { - this.value = isolate; - } - - /** - * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() - */ - @Override - LinkMessageImpl cloneMessage() { - return new IsolateLinkMessage(value); - } - - /** - * @see javax.isolate.LinkMessage#extract() - */ - @Override - public Object extract() { - return extractIsolate(); - } - - /** - * @see javax.isolate.LinkMessage#containsIsolate() - */ - @Override - public boolean containsIsolate() { - return true; - } - - /** - * @see javax.isolate.LinkMessage#extractIsolate() - */ - @Override - public Isolate extractIsolate() { - return value.getIsolate(); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/LinkImpl.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/LinkImpl.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/LinkImpl.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,98 +0,0 @@ -/* - * $Id: DataLinkImpl.java 4552 2008-09-11 11:38:42Z crawley $ - */ -package org.jnode.vm.isolate.link; - -import java.io.IOException; -import java.io.InterruptedIOException; - -import javax.isolate.ClosedLinkException; -import javax.isolate.Isolate; -import javax.isolate.Link; -import javax.isolate.LinkMessage; - -final class LinkImpl extends Link { - - private final VmLink vmLink; - - /** - * Constructor - * - * @param vmLink - */ - LinkImpl(VmLink vmLink) { - this.vmLink = vmLink; - } - - final VmLink getImpl() { - return vmLink; - } - - /** - * @see javax.isolate.Link#close() - */ - @Override - public void close() { - vmLink.close(); - } - - /** - * @see javax.isolate.Link#Equals(java.lang.Object) - */ - @Override - public boolean equals(Object other) { - if (other instanceof LinkImpl) { - return (((LinkImpl) other).vmLink == this.vmLink); - } - return false; - } - - /** - * @see javax.isolate.Link#getReceiver() - */ - @Override - public Isolate getReceiver() { - return vmLink.getReceiver().getIsolate(); - } - - /** - * @see javax.isolate.Link#getSender() - */ - @Override - public Isolate getSender() { - return vmLink.getSender().getIsolate(); - } - - /** - * @see javax.isolate.Link#isOpen() - */ - @Override - public boolean isOpen() { - return vmLink.isOpen(); - } - - /** - * @see javax.isolate.Link#receive() - */ - @Override - public LinkMessage receive() - throws ClosedLinkException, IllegalStateException, InterruptedIOException, IOException { - return vmLink.receive(); - } - - /** - * @see javax.isolate.Link#send(javax.isolate.LinkMessage) - */ - @Override - public void send(LinkMessage message) throws ClosedLinkException, InterruptedIOException, IOException { - vmLink.send(message); - } - - /** - * @see javax.isolate.Link#toString() - */ - @Override - public String toString() { - return vmLink.toString(); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/LinkLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,53 +0,0 @@ -/* - * $Id$ - */ -package org.jnode.vm.isolate.link; - -import javax.isolate.Link; - - -final class LinkLinkMessage extends LinkMessageImpl { - - private final VmLink value; - - /** - * Message constructor - * - * @param value - */ - LinkLinkMessage(VmLink link) { - this.value = link; - } - - /** - * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() - */ - @Override - LinkMessageImpl cloneMessage() { - return new LinkLinkMessage(value); - } - - /** - * @see javax.isolate.LinkMessage#extract() - */ - @Override - public Object extract() { - return extractLink(); - } - - /** - * @see javax.isolate.LinkMessage#containsLink() - */ - @Override - public boolean containsLink() { - return true; - } - - /** - * @see javax.isolate.LinkMessage#extractLink() - */ - @Override - public Link extractLink() { - return value.asLink(); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageFactory.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageFactory.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageFactory.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,84 +0,0 @@ -/* - * $Id$ - */ -package org.jnode.vm.isolate.link; - -import java.net.ServerSocket; -import java.net.Socket; - -import javax.isolate.Link; -import javax.isolate.LinkMessage; - -import org.jnode.vm.isolate.VmIsolate; - -public final class LinkMessageFactory { - - /** - * Create a LinkMessage containing the given link messages. - * - * @param messages - * @return - */ - public static LinkMessage newCompositeMessage(LinkMessage... messages) { - throw new UnsupportedOperationException(); - } - - /** - * Create a LinkMessage containing the given data. - * - * @param bytes - * @return - */ - public static LinkMessage newDataMessage(byte[] bytes, - int offset, - int length) { - return new DataLinkMessage(bytes, offset, length); - } - - /** - * Create a LinkMessage containing the given isolate. - * - * @param isolate - * @return - */ - public static LinkMessage newIsolateMessage(VmIsolate isolate) { - throw new UnsupportedOperationException(); - } - - /** - * Create a LinkMessage containing the given link. - * - * @return - */ - public static LinkMessage newLinkMessage(Link link) { - return new LinkLinkMessage(((LinkImpl) link).getImpl()); - } - - /** - * Create a LinkMessage containing the given server socket. - * - * @return - */ - public static LinkMessage newServerSocketMessage(ServerSocket socket) { - throw new UnsupportedOperationException(); - } - - /** - * Create a LinkMessage containing the given socket. - * - * @return - */ - public static LinkMessage newSocketMessage(Socket socket) { - throw new UnsupportedOperationException(); - } - - /** - * Create a LinkMessage containing the given string. - * - * @param string - * @return - */ - public static LinkMessage newStringMessage(String string) { - return new StringLinkMessage(string); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/LinkMessageImpl.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,44 +0,0 @@ -/* - * $Id$ - */ -package org.jnode.vm.isolate.link; - -import javax.isolate.LinkMessage; - -/** - * Base class for all types of LinkMessage implementation classes. - * - * @author Ewout Prangsma (ep...@us...) - */ -abstract class LinkMessageImpl extends LinkMessage { - - private boolean received = false; - - /** - * Close this message in the current isolate. - * - * @return - */ - abstract LinkMessageImpl cloneMessage(); - - /** - * Block the current thread, until this message has its received flag set. - */ - final void waitUntilReceived() throws InterruptedException { - if (!received) { - synchronized (this) { - while (!received) { - wait(); - } - } - } - } - - /** - * Mark this message as received and notify all waiting threads. - */ - final synchronized void notifyReceived() { - this.received = true; - notifyAll(); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/ObjectLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,50 +0,0 @@ -/* - * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library 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 Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.jnode.vm.isolate.link; - -/** - * This message type passes an object by reference. This is probably a bad idea - * because it 'breaks' the isolation of isolates. Use sparingly if at all. - * - * @author cr...@jn... - */ -public class ObjectLinkMessage extends LinkMessageImpl { - - private final Object obj; - - private ObjectLinkMessage(Object cr) { - this.obj = cr; - } - - public static ObjectLinkMessage newMessage (Object obj) { - return new ObjectLinkMessage(obj); - } - - @Override - public Object extract() { - return obj; - } - - @Override - LinkMessageImpl cloneMessage() { - return new ObjectLinkMessage(obj); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/StatusLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,90 +0,0 @@ -/* - * $Id: VmIsolate.java 4592 2008-09-30 12:00:11Z crawley $ - * - * JNode.org - * Copyright (C) 2003-2006 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library 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 Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.jnode.vm.isolate.link; - -import javax.isolate.IsolateStatus; - -/** - * This class is use to transport status isolate information - * @author cr...@jn... - */ -public final class StatusLinkMessage extends LinkMessageImpl { - - private final String state; - private final String exitReason; - private final int exitCode; - - /** - * Internal message constructor used by cloneMessage - * - * @param value - */ - private StatusLinkMessage(String state, String exitReason, int exitCode) { - this.state = state; - this.exitReason = exitReason; - this.exitCode = exitCode; - } - - /** - * Message constructor used VmIsolate - * - * @param value - */ - public StatusLinkMessage(IsolateStatus.State state, IsolateStatus.ExitReason exitReason, - int exitCode) { - this(state.toString(), exitReason.toString(), exitCode); - } - - /** - * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() - */ - @Override - LinkMessageImpl cloneMessage() { - return new StatusLinkMessage(state, exitReason, exitCode); - } - - /** - * @see javax.isolate.LinkMessage#extract() - */ - @Override - public Object extract() { - return extractStatus(); - } - - /** - * @see javax.isolate.LinkMessage#containsString() - */ - @Override - public boolean containsStatus() { - return true; - } - - /** - * @see javax.isolate.LinkMessage#extractString() - */ - @Override - public IsolateStatus extractStatus() { - return new IsolateStatus( - IsolateStatus.State.valueOf(state), - IsolateStatus.ExitReason.valueOf(exitReason), - exitCode); - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/StringLinkMessage.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,51 +0,0 @@ -/* - * $Id$ - */ -package org.jnode.vm.isolate.link; - - -final class StringLinkMessage extends LinkMessageImpl { - - private final String value; - - /** - * Message constructor - * - * @param value - */ - StringLinkMessage(String value) { - this.value = value; - } - - /** - * @see org.jnode.vm.isolate.LinkMessageImpl#CloneMessage() - */ - @Override - LinkMessageImpl cloneMessage() { - return new StringLinkMessage(new String(value)); - } - - /** - * @see javax.isolate.LinkMessage#extract() - */ - @Override - public Object extract() { - return extractString(); - } - - /** - * @see javax.isolate.LinkMessage#containsString() - */ - @Override - public boolean containsString() { - return true; - } - - /** - * @see javax.isolate.LinkMessage#extractString() - */ - @Override - public String extractString() { - return value; - } -} Deleted: trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java =================================================================== --- trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java 2008-10-02 13:24:26 UTC (rev 4595) +++ trunk/core/src/core/org/jnode/vm/isolate/link/VmLink.java 2008-10-02 13:42:14 UTC (rev 4596) @@ -1,288 +0,0 @@ -/* - * $Id: VmDataLink.java 4552 2008-09-11 11:38:42Z crawley $ - */ -package org.jnode.vm.isolate.link; - -import java.io.IOException; -import java.io.InterruptedIOException; -import java.util.LinkedList; -import java.util.Queue; - -import javax.isolate.ClosedLinkException; -import javax.isolate.Link; -import javax.isolate.LinkMessage; - -import org.jnode.vm.isolate.VmIsolate; -import org.jnode.vm.isolate.VmIsolateLocal; - -/** - * Shared implementation of javax.isolate.Link - * - * @author Ewout Prangsma (ep...@us...) - */ -public final class VmLink { - - private final VmIsolateLocal<LinkImpl> linkHolder = new VmIsolateLocal<LinkImpl>(); - - private final Queue<LinkMessageImpl> messages = new LinkedList<LinkMessageImpl>(); - - private boolean closed = false; - - private VmIsolate sender; - - private VmIsolate receiver; - - /** - * Create a new data link between the given isolates. - * - * @param sender - * @param receiver - * @return - */ - public static Link newLink(VmIsolate sender, VmIsolate receiver) { - if (sender == receiver) { - throw new IllegalArgumentException("sender == receiver"); - } - VmLink vmLink = new VmLink(sender, receiver); - return vmLink.asLink(); - } - - public static VmLink fromLink(Link link) { - return ((LinkImpl) link).getImpl(); - } - - /** - * @param sender - * @param receiver - */ - VmLink(VmIsolate sender, VmIsolate receiver) { - this.sender = sender; - this.receiver = receiver; - } - - /** - * Gets this shared link as Link instance. - * - * @return - */ - public final Link asLink() { - final LinkImpl link = linkHolder.get(); - if (link == null) { - linkHolder.set(new LinkImpl(this)); - return linkHolder.get(); - } else { - return link; - } - } - - /** - * Close this link. - */ - final void close() { - if (!this.closed) { - final VmIsolate current = VmIsolate.currentIsolate(); - if ((current != receiver) && (current != sender)) { - throw new IllegalStateException( - "Only sender or receiver can close this link"); - } - this.closed = true; - synchronized (this) { - notifyAll(); - } - } - } - - /** - * Is this link currently open. - * - * @return - */ - final boolean isOpen() { - return !closed; - } - - /** - * @return the receiver - */ - final VmIsolate getReceiver() { - return receiver; - } - - /** - * @return the sender - */ - final VmIsolate getSender() { - return sender; - } - - /** - * Receives a copy of a message sent on this Link. - * <p/> - * The current thread will block in this method until a sender is available. - * When the sender and receiver rendezvous, the message will then be - * transferred. If multiple threads invoke this method on the same object, - * only one thread will receive any message at rendezvous and the other - * threads will contend for subsequent access to the rendezvous point. A - * normal return indicates that the message was received successfully. If an - * exception occured on the sender side, no rendezvous will occur, and no - * object will be transferred; the receiver will wait for the next - * successful send. If an exception occurs on the receive, the sender will - * see a successful transfer. - * <p/> - * This method never returns null. - * <p/> - * If the sending isolate becomes terminated after this method is invoked - * but before it returns, the link will be closed, a ClosedLinkException - * will be thrown, any subsequent attempts to use receive() will result in a - * ClosedLinkException, and any Isolate objects corresponding to the receive - * side of the link will reflect a terminated state. - * <p/> - * If invoked on a closed Link, this method will throw a - * ClosedLinkException. - * <p/> - * If close() is invoked on the link while a thread is blocked in receive(), - * receive() will throw a ClosedLinkException. No message will have been - * transferred in that case. - * <p/> - * If Thread.interrupt() is invoked on a thread that has not yet completed - * an invocation of this method, the results are undefined. An - * InterruptedIOException may or may not be thrown; if not, control will - * return from the method with a valid LinkMessage object. However, even if - * InterruptedIOException is thrown, rendezvous and data transfer from the - * sending isolate may have occurred. In particular, undetected message loss - * between sender and receiver may occur. - * <p/> - * If a failure occurs due to the object being transferred between isolates - * an IOException may be thrown in the receiver. For example, if a message - * containing a large buffer is sent and the receiver has insufficient heap - * memory for the buffer or if construction of a link in the receiver - * isolate fails, an IOException will be thrown. The sender will see a - * successful transfer in these cases. - * <p/> - * If the current isolate is not a receiver on this Link an - * IllegalStateException will be thrown. The receiver will not rendezvous - * with a sender in this case. - * - * @return - */ - final LinkMessage receive() throws ClosedLinkException, - IllegalStateException, InterruptedIOException, IOException { - if (VmIsolate.currentIsolate() != receiver) { - // Current isolate is not the receiver - throw new IllegalStateException(); - } - if (this.closed) { - throw new ClosedLinkException(); - } - final LinkMessageImpl message; - synchronized (this) { - while (messages.isEmpty()) { - if (this.closed) { - throw new ClosedLinkException(); - } - try { - wait(); - } catch (InterruptedException ex) { - throw new InterruptedIOException(); - } - } - message = messages.poll(); - } - message.notifyReceived(); - return message.cloneMessage(); - } - - /** - * Sends the given message on this Link. - * <p/> - * The current thread will block in this method until a receiver is - * available. When the sender and receiver rendezvous, the message will then - * be transferred. A normal return indicates that the message was - * transferred. If an exception occurs on the sender side, no rendezvous - * will occur and no object will be transferred. But if an exception occurs - * on the receive(), the sender will see a successful transfer. - * <p/> - * If the receiving isolate becomes terminated after this method is invoked - * but before it returns, the link will be closed, a ClosedLinkException - * will be thrown, any subsequent attempts to use send() will result in a - * ClosedLinkException, and any Isolate objects corresponding to the receive - * side of the link will reflect a terminated state. - * <p/> - * If invoked on a closed link, this method will throw a - * ClosedLinkException. - * <p/> - * If close() is invoked on this Link while a thread is blocked in send(), - * send() will throw a ClosedLinkException. No message will have been - * transferred in that case. - * <p/> - * If Thread.interrupt() is invoked on a thread that has not yet completed - * an invocation of this method, the results are undefined. An - * InterruptedIOException may or may not be thrown; however, even if not, - * control will return from the method. Rendezvous and data transfer to the - * receiving isolate may or may not have occurred. In particular, undetected - * message loss between sender and receiver may occur. - * <p/> - * If a failure occurs during the transfer an IOException may be thrown in - * the sender and the object will not be sent. A transfer may succeed from - * the sender's point of view, but cause an independent IOException in the - * receiver. For example, if a message containing a large buffer is sent and - * the receiver has insufficient heap memory for the buffer or if - * construction of a link in the receiver isolate fails, an IOException will - * be thrown in the receiver after the transfer completes. - * <p/> - * A ClosedLinkException will be thrown if the given LinkMessage contains a - * closed Link, Socket, or ServerSocket. No object will be transferred in - * this case. - * <p/> - * If the current isolate is not a sender on this Link, an - * UnsupportedOperationException will be thrown. No object will be sent in - * this case. - * - * @param message - * @throws ClosedLinkException - * @throws InterruptedIOException - * @throws IOException - */ - final void send(LinkMessage message) throws ClosedLinkException, - InterruptedIOException, IOException { - if (VmIsolate.currentIsolate() != sender) { - // Current isolate is not the sender for this message - throw new UnsupportedOperationException(); - } - if (this.closed) { - throw new ClosedLinkException(); - } - final LinkMessageImpl messageImpl = (LinkMessageImpl) message; - synchronized (this) { - if (this.closed) { - throw new ClosedLinkException(); - } - // Send message - messages.add(messageImpl); - notifyAll(); - } - - // Wait for the message to be picked up by the receiver - try { - messageImpl.wa... [truncated message content] |