CVS: beepcore-java/src/org/beepcore/beep/core PiggybackedMSG.java,NONE,1.1.2.1 ChannelImpl.java,1.7,1.7.2.1 TuningProfile.java,1.10,1.10.2.1 SessionImpl.java,1.8,1.8.2.1

Huston Franklin <[email protected]> Sun, 13 Jul 2003 07:27:48 -0700
Newsgroups gmane.network.beep.beepcore.java.cvs
Message-ID <[email protected]>
Update of /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core
In directory sc8-pr-cvs1:/tmp/cvs-serv2246/src/org/beepcore/beep/core

Modified Files:
      Tag: PIGGYBACKED
	ChannelImpl.java TuningProfile.java SessionImpl.java 
Added Files:
      Tag: PIGGYBACKED
	PiggybackedMSG.java 
Log Message:
Initial piggybacked changes

--- NEW FILE: PiggybackedMSG.java ---
/*
 * RequestHandler.java  $Revision: 1.1.2.1 $ $Date: 2003/07/13 14:27:46 $
 *
 * Copyright (c) 2003 Huston Franklin.  All rights reserved.
 *
 * The contents of this file are subject to the Blocks Public License (the
 * "License"); You may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at http://www.beepcore.org/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 */
package org.beepcore.beep.core;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;

import org.beepcore.beep.util.BufferSegment;

/**
 * This class is used to wrap piggybacked data from the start channel request.
 *
 * @author Huston Franklin
 * @version $Revision: 1.1.2.1 $, $Date: 2003/07/13 14:27:46 $
 */
class PiggybackedMSG extends MessageMSGImpl implements MessageMSG {

    PiggybackedMSG(ChannelImpl channel, byte[] data, boolean base64encoding)
    {
        super(channel, -1, new InputDataStream());
        try {
            this.getDataStream().add(new BufferSegment("\r\n".getBytes("UTF-8"))); 
        } catch (UnsupportedEncodingException e) {
            this.channel.getSession().terminate("UTF-8 not supported");
            return;
        }
        this.getDataStream().add(new BufferSegment(data));
        this.getDataStream().setComplete();
    }
    
	public MessageStatus sendANS(OutputDataStream stream)
		throws BEEPException
    {
        throw new BEEPException("ANS reply not valid for piggybacked requests");
	}

	public MessageStatus sendERR(BEEPError error) throws BEEPException {
        throw new BEEPException("ERR reply not valid for piggybacked requests");
	}

	public MessageStatus sendERR(int code, String diagnostic)
		throws BEEPException
    {
        throw new BEEPException("ERR reply not valid for piggybacked requests");
	}

	public MessageStatus sendERR(int code, String diagnostic, String xmlLang)
		throws BEEPException
    {
        throw new BEEPException("ERR reply not valid for piggybacked requests");
	}

	public MessageStatus sendNUL() throws BEEPException {
        throw new BEEPException("ANS reply not valid for piggybacked requests");
	}

	public MessageStatus sendRPY(OutputDataStream stream)
		throws BEEPException
    {
        SessionImpl s = (SessionImpl)this.channel.getSession();
        ByteArrayOutputStream tmp =
            new ByteArrayOutputStream(SessionImpl.MAX_PCDATA_SIZE);
        String data;

        while (stream.availableSegment()) {
            BufferSegment b = stream.getNextSegment(SessionImpl.MAX_PCDATA_SIZE);

            tmp.write(b.getData(), 0, b.getLength());
        }

        try {
            data = tmp.toString("UTF-8");
            int crlf = data.indexOf("\r\n");
            if (crlf != -1) {
                data = data.substring(crlf + "\r\n".length());
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 not supported");
        }

        try {
            s.sendProfile(this.channel.getProfile(), data, this.channel);
        } catch (BEEPException e) {
            s.terminate("Error sending profile. " + e.getMessage());
            throw e;
        }

        s.fireChannelStarted(this.channel);
        
        return new MessageStatus(this.channel, Message.MESSAGE_TYPE_RPY, -1,
                                 stream);
	}
}

Index: ChannelImpl.java
===================================================================
RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core/ChannelImpl.java,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -C2 -r1.7 -r1.7.2.1
*** ChannelImpl.java	10 Jun 2003 18:59:17 -0000	1.7
--- ChannelImpl.java	13 Jul 2003 14:27:46 -0000	1.7.2.1
***************
*** 419,422 ****
--- 419,438 ----
      }
  
+     void abort()
+     {
+         setState(ChannelImpl.STATE_ABORTED);
+     }
+ 
+     void addPiggybackedMSG(PiggybackedMSG msg) throws BEEPException
+     {
+         recvMSGQueue.add(msg);
+         try {
+             callbackQueue.execute(this);
+         } catch (InterruptedException e) {
+             /** @TODO handle this better */
+             throw new BEEPException(e);
+         }
+     }
+ 
      /**
       * get the number of this <code>Channel</code> as a <code>String</code>

Index: TuningProfile.java
===================================================================
RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core/TuningProfile.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -C2 -r1.10 -r1.10.2.1
*** TuningProfile.java	27 May 2003 21:37:41 -0000	1.10
--- TuningProfile.java	13 Jul 2003 14:27:46 -0000	1.10.2.1
***************
*** 75,79 ****
       *
       */
!     public void abort(BEEPError error, Channel channel) throws BEEPException
      {
          tuningChannels.remove(channel);
--- 75,79 ----
       *
       */
!     public void abort(BEEPError error, Channel channel)
      {
          tuningChannels.remove(channel);
***************
*** 120,123 ****
--- 120,132 ----
          }
      }
+     
+     protected void begin(Channel channel)
+     {
+         log.debug("TuningProfile.begin");
+ 
+         SessionImpl session = (SessionImpl)channel.getSession();
+ 
+         ((ChannelImpl)channel).setState(ChannelImpl.STATE_TUNING);
+     }
  
      /**
***************
*** 134,142 ****
       */
      public void complete(Channel channel,
!                           SessionCredential localCred,
!                           SessionCredential peerCred,
!                           SessionTuningProperties tuning,
!                           ProfileRegistry registry,
!                           Object argument)
          throws BEEPException
      {
--- 143,151 ----
       */
      public void complete(Channel channel,
!                          SessionCredential localCred,
!                          SessionCredential peerCred,
!                          SessionTuningProperties tuning,
!                          ProfileRegistry registry,
!                          Object argument)
          throws BEEPException
      {

Index: SessionImpl.java
===================================================================
RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core/SessionImpl.java,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -C2 -r1.8 -r1.8.2.1
*** SessionImpl.java	10 Jun 2003 18:59:19 -0000	1.8
--- SessionImpl.java	13 Jul 2003 14:27:46 -0000	1.8.2.1
***************
*** 21,24 ****
--- 21,25 ----
  
  import java.io.IOException;
+ import java.io.UnsupportedEncodingException;
  
  import java.util.Hashtable;
***************
*** 38,41 ****
--- 39,44 ----
  import org.xml.sax.SAXException;
  
+ import sun.misc.BASE64Decoder;
+ 
  import org.beepcore.beep.core.event.ChannelEvent;
  import org.beepcore.beep.core.event.ChannelListener;
***************
*** 86,90 ****
  
      /** @todo check this */
!     private static final int MAX_PCDATA_SIZE = 4096;
      private static final int MAX_START_CHANNEL_WAIT = 60000;
      private static final int MAX_START_CHANNEL_INTERVAL = 100;
--- 89,93 ----
  
      /** @todo check this */
!     static final int MAX_PCDATA_SIZE = 4096;
      private static final int MAX_START_CHANNEL_WAIT = 60000;
      private static final int MAX_START_CHANNEL_INTERVAL = 100;
***************
*** 977,981 ****
      }
  
!     private void fireChannelStarted(Channel c)
      {
          ChannelListener[] l = this.channelListeners;
--- 980,984 ----
      }
  
!     void fireChannelStarted(Channel c)
      {
          ChannelListener[] l = this.channelListeners;
***************
*** 1244,1247 ****
--- 1247,1252 ----
                  return;
              } catch (StartChannelException e) {
+                 this.enableIO();
+ 
                  try {
                      ((MessageMSG)zero.getAppData()).sendERR(e);
***************
*** 1253,1265 ****
              }
  
!             try {
!                 sendProfile(p.uri, ch.getStartData(), ch);
!             } catch (BEEPException e) {
!                 terminate("Error sending profile. " + e.getMessage());
  
!                 return;
!             }
  
!             fireChannelStarted(ch);
  
              if (p.data == null || ch.getState() != ChannelImpl.STATE_TUNING) {
--- 1258,1304 ----
              }
  
!             if (p.data != null && ch.getStartData() == null) {
!                 byte[] data;
!                 if (p.base64Encoding) {
!                     try {
!                         data = new BASE64Decoder().decodeBuffer(p.data);
!                     } catch (IOException e) {
!                         ch.abort();
!                         this.enableIO();
!                         throw new BEEPError(BEEPError.CODE_REQUESTED_ACTION_ABORTED,
!                                             "Error parsing piggybacked data.");
!                     }
!                 } else {
!                     try {
!                         data = p.data.getBytes("UTF-8"); 
!                     } catch (UnsupportedEncodingException e) {
!                         terminate("UTF-8 not supported");
!                         return;
!                     }
!                 }
!                 
!                 PiggybackedMSG msg = new PiggybackedMSG(ch, data,
!                                                         p.base64Encoding);
  
!                 ch.setState(ChannelImpl.STATE_STARTING);
  
!                 try {
!                     ch.addPiggybackedMSG(msg);
!                 } catch (BEEPException e) {
!                     terminate("Error sending profile. " + e.getMessage());
! 
!                     return;
!                 }
!             } else {
!                 try {
!                     sendProfile(p.uri, ch.getStartData(), ch);
!                 } catch (BEEPException e) {
!                     terminate("Error sending profile. " + e.getMessage());
! 
!                     return;
!                 }
! 
!                 fireChannelStarted(ch);
!             }
  
              if (p.data == null || ch.getState() != ChannelImpl.STATE_TUNING) {
***************
*** 1269,1272 ****
--- 1308,1313 ----
              return;
          }
+ 
+         this.enableIO();
  
          try {



-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1