Package org.xmlBlaster.util.xbformat

Examples of org.xmlBlaster.util.xbformat.I_ProgressListener


   /**
    * Flush the data to the socket.
    * Overwrites SocketExecutor.sendMessage()
    */
   protected void sendMessage(byte[] msg, boolean udp) throws IOException {
      I_ProgressListener listener = this.progressListener;
      try {
         if (listener != null) {
            listener.progressWrite("", 0, msg.length);
         }
         else
            log.fine("The progress listener is null");

         if (udp && this.sockUDP!=null && this.sock!=null) {
            DatagramPacket dp = new DatagramPacket(msg, msg.length, this.sock.getInetAddress(), this.sock.getPort());
            //DatagramPacket dp = new DatagramPacket(msg, msg.length, sock.getInetAddress(), 32001);
            this.sockUDP.send(dp);
            if (log.isLoggable(Level.FINE)) log.fine("UDP datagram is send");
         }
         else {
            int bytesLeft = msg.length;
            int bytesRead = 0;
            synchronized (oStream) {
               while (bytesLeft > 0) {
                  int toRead = bytesLeft > this.maxChunkSize ? this.maxChunkSize : bytesLeft;
                  oStream.write(msg, bytesRead, toRead);
                  oStream.flush();
                  bytesRead += toRead;
                  bytesLeft -= toRead;
                  if (listener != null)
                     listener.progressWrite("", bytesRead, msg.length);
               }
            }
         }
         if (listener != null) {
            listener.progressWrite("", msg.length, msg.length);
         }
      }
      catch (IOException ex) {
         if (listener != null) {
            listener.clearCurrentWrites();
            listener.clearCurrentReads();
         }
         throw ex;
      }
   }
View Full Code Here


   public Object xmlScriptInvoke(String literal) throws XmlBlasterException {
      if (log.isLoggable(Level.FINER))
         log.finer("xmlScriptInvoke: " + literal);
     
      XmlScriptParser parser = new XmlScriptParser();
      final I_ProgressListener progressListener = null;
      final I_PluginConfig pluginConfig = null;
      parser.init(glob, progressListener, pluginConfig);
      InputStream is = new ByteArrayInputStream(literal.getBytes());
      try {
         MsgInfo[] msgInfoArr = parser.parse(is);
View Full Code Here

   public Object xmlScriptInvoke(String literal) throws XmlBlasterException {
      if (log.isLoggable(Level.FINER))
         log.finer("xmlScriptInvoke: " + literal);
     
      XmlScriptParser parser = new XmlScriptParser();
      final I_ProgressListener progressListener = null;
      final I_PluginConfig pluginConfig = null;
      parser.init(glob, progressListener, pluginConfig);
     
      InputStream is = new ByteArrayInputStream(literal.getBytes());
      try {
View Full Code Here

      SocketExecutor cbRec = getCbReceiver();
      if (cbRec != null)
         return cbRec.registerProgressListener(listener);
      else {
         if (log.isLoggable(Level.FINE)) log.fine("The callback receiver is null, will be registered when the callback receiver is registered.");
         I_ProgressListener ret = this.tmpProgressListener;
         this.tmpProgressListener = listener;
         return ret;
      }
   }
View Full Code Here

    * @return "SOCKET" or "EMAIL", never null
    */
   abstract public String getType();

   public I_ProgressListener registerProgressListener(I_ProgressListener listener) {
      I_ProgressListener oldOne = this.progressListener;
      this.progressListener = listener;
      return oldOne;
   }
View Full Code Here

   /**
    * Flush the data to the socket.
    * Overwrite this in your derived class to send UDP
    */
   protected void sendMessage(MsgInfo msgInfo, String requestId, MethodName methodName, boolean udp) throws XmlBlasterException, IOException {
      I_ProgressListener listener = this.progressListener;
      try {
         // TODO: On server side the msgInfoParserClassName should be from CbSocketDriver configuration
         byte[] msg = msgInfo.createRawMsg(getCbMsgInfoParserClassName());
         if (log.isLoggable(Level.FINEST)) log.finest("Sending TCP data of length " + msg.length + " >" + XbfParser.createLiteral(msg) + "<");
         if (listener != null) {
            listener.progressWrite("", 0, msg.length);
         }
         else
            log.fine("The progress listener is null");

         int bytesLeft = msg.length;
         int bytesRead = 0;
         if (oStream == null)
            throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "sendMessage() invocation ignored, we are shutdown.");
         synchronized (oStream) {
            while (bytesLeft > 0) {
               int toRead = bytesLeft > this.maxChunkSize ? this.maxChunkSize : bytesLeft;
               oStream.write(msg, bytesRead, toRead);
               oStream.flush();
               bytesRead += toRead;
               bytesLeft -= toRead;
               if (listener != null)
                  listener.progressWrite("", bytesRead, msg.length);
            }
            if (this.isNullTerminated) { // If using XmlScriptInterpreter as parserClass, we finish each script with a null byte
               oStream.write(0);
               oStream.flush();
            }
            if (log.isLoggable(Level.FINE)) log.fine("TCP data is send");
         }
         if (listener != null) {
            listener.progressWrite("", msg.length, msg.length);
         }

      }
      catch (IOException ex) {
         if (listener != null) {
            listener.clearCurrentWrites();
            listener.clearCurrentReads();
         }
         throw ex;
      }
      catch (XmlBlasterException ex) {
         if (listener != null) {
            listener.clearCurrentWrites();
            listener.clearCurrentReads();
         }
         throw ex;
      }
   }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.xbformat.I_ProgressListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.