Ejemplo n.º 1
0
 private void initializeReading() throws JMSException {
   checkWriteOnlyBody();
   if (dataIn == null) {
     ByteSequence data = getContent();
     if (data == null) {
       data = new ByteSequence(new byte[] {}, 0, 0);
     }
     InputStream is = new ByteArrayInputStream(data);
     if (isCompressed()) {
       // keep track of the real length of the content if
       // we are compressed.
       try {
         DataInputStream dis = new DataInputStream(is);
         length = dis.readInt();
         dis.close();
       } catch (IOException e) {
         throw JMSExceptionSupport.create(e);
       }
       is = new InflaterInputStream(is);
     } else {
       length = data.getLength();
     }
     dataIn = new DataInputStream(is);
   }
 }
Ejemplo n.º 2
0
 /**
  * Writes a portion of a byte array to the bytes message stream.
  *
  * @param value the byte array value to be written
  * @param offset the initial offset within the byte array
  * @param length the number of bytes to use
  * @throws JMSException if the JMS provider fails to write the message due to some internal error.
  * @throws MessageNotWriteableException if the message is in read-only mode.
  */
 @Override
 public void writeBytes(byte[] value, int offset, int length) throws JMSException {
   initializeWriting();
   try {
     this.dataOut.write(value, offset, length);
   } catch (IOException ioe) {
     throw JMSExceptionSupport.create(ioe);
   }
 }
Ejemplo n.º 3
0
 /**
  * Writes a string to the bytes message stream using UTF-8 encoding in a machine-independent
  * manner.
  *
  * <p>For more information on the UTF-8 format, see "File System Safe UCS Transformation Format
  * (FSS_UTF)", X/Open Preliminary Specification, X/Open Company Ltd., Document Number: P316. This
  * information also appears in ISO/IEC 10646, Annex P.
  *
  * @param value the <code>String</code> value to be written
  * @throws JMSException if the JMS provider fails to write the message due to some internal error.
  * @throws MessageNotWriteableException if the message is in read-only mode.
  */
 @Override
 public void writeUTF(String value) throws JMSException {
   initializeWriting();
   try {
     this.dataOut.writeUTF(value);
   } catch (IOException ioe) {
     throw JMSExceptionSupport.create(ioe);
   }
 }
Ejemplo n.º 4
0
 @Override
 protected Message copy(Session session, Message m) throws JMSException {
   if (m instanceof ActiveMQBlobMessage) {
     ActiveMQBlobMessage b = (ActiveMQBlobMessage) m;
     ActiveMQBlobMessage copy =
         (ActiveMQBlobMessage) getAMQSession(session).createBlobMessage(b.getURL());
     try {
       copy.setProperties(b.getProperties());
     } catch (IOException e) {
       throw JMSExceptionSupport.create("Unable to copy message " + m, e);
     }
     return copy;
   } else {
     return super.copy(session, m);
   }
 }
Ejemplo n.º 5
0
  private void beforeEnd() throws JMSException {
    if (synchronizations == null) {
      return;
    }

    int size = synchronizations.size();
    try {
      for (; beforeEndIndex < size; ) {
        synchronizations.get(beforeEndIndex++).beforeEnd();
      }
    } catch (JMSException e) {
      throw e;
    } catch (Throwable e) {
      throw JMSExceptionSupport.create(e);
    }
  }
Ejemplo n.º 6
0
  private void initializeWriting() throws JMSException {
    checkReadOnlyBody();
    if (this.dataOut == null) {
      this.bytesOut = new ByteArrayOutputStream();
      OutputStream os = bytesOut;
      ActiveMQConnection connection = getConnection();
      if (connection != null && connection.isUseCompression()) {
        // keep track of the real length of the content if
        // we are compressed.
        try {
          os.write(new byte[4]);
        } catch (IOException e) {
          throw JMSExceptionSupport.create(e);
        }
        length = 0;
        compressed = true;
        final Deflater deflater = new Deflater(Deflater.BEST_SPEED);
        os =
            new FilterOutputStream(new DeflaterOutputStream(os, deflater)) {
              @Override
              public void write(byte[] arg0) throws IOException {
                length += arg0.length;
                out.write(arg0);
              }

              @Override
              public void write(byte[] arg0, int arg1, int arg2) throws IOException {
                length += arg2;
                out.write(arg0, arg1, arg2);
              }

              @Override
              public void write(int arg0) throws IOException {
                length++;
                out.write(arg0);
              }

              @Override
              public void close() throws IOException {
                super.close();
                deflater.end();
              }
            };
      }
      this.dataOut = new DataOutputStream(os);
    }
  }
 // DiscoveryAgent interface
 // -------------------------------------------------------------------------
 public void start() throws Exception {
   if (group == null) {
     throw new IOException("You must specify a group to discover");
   }
   String type = getType();
   if (!type.endsWith(".")) {
     LOG.warn("The type '" + type + "' should end with '.' to be a valid Rendezvous type");
     type += ".";
   }
   try {
     // force lazy construction
     getJmdns();
     if (listener != null) {
       LOG.info("Discovering service of type: " + type);
       jmdns.addServiceListener(type, this);
     }
   } catch (IOException e) {
     JMSExceptionSupport.create("Failed to start JmDNS service: " + e, e);
   }
 }
Ejemplo n.º 8
0
  private void afterCommit() throws JMSException {
    if (synchronizations == null) {
      return;
    }

    Throwable firstException = null;
    int size = synchronizations.size();
    for (int i = 0; i < size; i++) {
      try {
        synchronizations.get(i).afterCommit();
      } catch (Throwable t) {
        LOG.debug("Exception from afterCommit on {}", synchronizations.get(i), t);
        if (firstException == null) {
          firstException = t;
        }
      }
    }
    synchronizations = null;
    if (firstException != null) {
      throw JMSExceptionSupport.create(firstException);
    }
  }