21 Jun 2005 21:55
request for non blocking Stream open and close
Jacques Belissent <jacques.belissent <at> sun.com>
2005-06-21 19:55:16 GMT
2005-06-21 19:55:16 GMT
Stream#open sends the outbound stream opener and waits for the inbound stream opener. Similarly Stream#close waits for the inbound closing stream tag. Instead of waiting for a packet coming from the remote end, it is sometimes more efficient to return right away and continue the processing when the expected StreamStatusListener#statusChanged callback is invoked. This also requires that timeouts be handled otherwise. In order to make this an option, I would like to suggest the following: 1. expose openOutbound as a public method 2. add a closeOutbound method There is another issue addressed by the attached diffs: When multiple packets are received in a short amount of time, we noticed that JSO parses them all in, and then invokes the packet listeners for all. Any reason why it does that? We found it preferable to process each packet after it is parsed. This helps in making sure that we don't take in more than we can process. Jacques
Index: AbstractStream.java
===================================================================
RCS file: /home/cvs/jso/src/net/outer_planes/jso/AbstractStream.java,v
retrieving revision 1.44
diff -r1.44 AbstractStream.java
104a105
> firePacketTransferredEvent(PacketEvent.RECEIVED);
833c834
< protected void openOutbound() throws StreamException {
---
> public void openOutbound() throws StreamException {
927,934c928
< try {
< setStreamException(se);
<
< //Try and send the closing
< if (getOutboundStatus().isOpened()) {
< _Outbound.sendClose(se);
< fireStatusChangedEvent(getOutboundContext(), Stream.CLOSED, se);
< }
---
> setStreamException(se);
935a930,932
> closeOutbound(se);
>
> try {
947,956c944
< if (se == null) {
< if (e instanceof StreamException)
< se = (StreamException)e;
< else {
< StreamError err = getDataFactory().createStreamError(StreamError.UNDEFINED_CONDITION);
<
< err.setText(e.getMessage());
< se = new StreamException(err);
< }
< }
---
> if (se == null) se = wrapException(e);
963a952,982
> public void closeOutbound() throws StreamException {
> closeOutbound(null);
> }
>
> public void closeOutbound(StreamException se) throws StreamException {
> if (!getOutboundStatus().isOpened())
> return;
> try {
> //Try and send the closing
> if (getOutboundStatus().isOpened()) {
> _Outbound.sendClose(se);
> fireStatusChangedEvent(getOutboundContext(), Stream.CLOSED, se);
> }
> } catch (Exception e) {
> obtainLogger().info("exception thrown while sending close", e);
> if (se == null) se = wrapException(e);
> throw se;
> }
> }
>
> private StreamException wrapException(Exception e) {
> StreamException se = null;
> if (e instanceof StreamException) {
> se = (StreamException)e;
> } else {
> StreamError err = getDataFactory().createStreamError(StreamError.UNDEFINED_CONDITION);
> err.setText(e.getMessage());
> se = new StreamException(err);
> }
> return se;
> }
1057c1076
< firePacketTransferredEvent(PacketEvent.RECEIVED);
---
> //firePacketTransferredEvent(PacketEvent.RECEIVED);
1092c1111
< }
\ No newline at end of file
---
> }
Index: Stream.java =================================================================== RCS file: /home/cvs/jso/src/org/jabberstudio/jso/Stream.java,v retrieving revision 1.28 diff -r1.28 Stream.java 438a439,472 > /** > * <p> > * Closes this outbound context for this <tt>Stream</tt>. > * This method returns immediately after sending the closing > * </stream:stream></p> > * > * <p> > * Any exception thrown is caught and re-thrown as a > * <tt>StreamException</tt>.</p> > * > * <p> > * The value of <tt>se</tt> may be <tt>null</tt>. If not, this method > * first sends a <stream:error/> using <tt>se</tt> before sending > * the closing tag.</p> > * > * <at> param se The <tt>StreamException</tt> closing this <tt>Stream</tt>. > * <at> throws StreamException If any errors are encountered. > * <at> since JSO-0.13 > */ > public void closeOutbound(StreamException se) throws StreamException; > /** > * <p> > * Closes this outbound context for this <tt>Stream</tt>. > * This method returns immediately after sending the closing > * </stream:stream></p> > * > * <p> > * Any exception thrown is caught and re-thrown as a > * <tt>StreamException</tt>.</p> > * > * <at> throws StreamException If any errors are encountered. > * <at> since JSO-0.13 > */ > public void closeOutbound() throws StreamException; 473c507,519 < } \ No newline at end of file --- > /** > * <p> > * Sends the opening <tt><stream:stream></tt> tag. > * > * <p> > * Any exception thrown is caught and re-thrown as a > * <tt>StreamException</tt>.</p> > * > * <at> throws StreamException If any errors are encountered. > * <at> since JSO-0.13 > */ > public void openOutbound() throws StreamException; > }
_______________________________________________ jso-devel mailing list jso-devel <at> jabberstudio.org http://mail.jabber.org/mailman/listinfo/jso-devel
RSS Feed