public static Object getOut(NettyEndpoint endpoint, Exchange exchange) { if (endpoint.getConfiguration().isTransferExchange()) { // we should transfer the entire exchange over the wire (includes in/out) return DefaultExchangeHolder.marshal(exchange); } else { // normal transfer using the body only return exchange.getOut().getBody(); } }
public static Object getOut(NettyEndpoint endpoint, Exchange exchange) { if (endpoint.getConfiguration().isTransferExchange()) { // we should transfer the entire exchange over the wire (includes in/out) return DefaultExchangeHolder.marshal(exchange); } else { // normal transfer using the body only return exchange.getOut().getBody(); } }
@Override public Exchange add(CamelContext camelContext, String key, Exchange exchange) { if (optimistic) { throw new UnsupportedOperationException(); } LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key); DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); DefaultExchangeHolder oldHolder = cache.getAndPut(key, newHolder); return unmarshallExchange(camelContext, oldHolder); }
@Override public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) { LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key); DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); DefaultExchangeHolder oldHolder = cache.put(key, newHolder); return unmarshallExchange(camelContext, oldHolder); }
public static Object getIn(NettyEndpoint endpoint, Exchange exchange) { if (endpoint.getConfiguration().isTransferExchange()) { // we should transfer the entire exchange over the wire (includes in/out) return DefaultExchangeHolder.marshal(exchange); } else { if (endpoint.getConfiguration().isUseChannelBuffer()) { // The NettyConverter could help us for it return exchange.getIn().getBody(ChannelBuffer.class); } else { // normal transfer using the body only return exchange.getIn().getBody(); } } }
@Override public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) { LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key); DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); DefaultExchangeHolder oldHolder = cache.put(key, newHolder); return unmarshallExchange(camelContext, oldHolder); }
private void checkAndStore(final Exchange exchange) { Object obj; Object body = exchange.getIn().getBody(); final HazelcastSedaEndpoint endpoint = (HazelcastSedaEndpoint) this.getEndpoint(); final HazelcastSedaConfiguration configuration = endpoint.getConfiguration(); if (configuration.isTransferExchange()) { obj = DefaultExchangeHolder.marshal(exchange); } else { // in case body is not serializable convert to byte array if (!(body instanceof Serializable)) { obj = exchange.getIn().getBody(byte[].class); } else { obj = body; } } queue.add(obj); // finally copy headers HazelcastComponentHelper.copyHeaders(exchange); }
@Override public Exchange add(CamelContext camelContext, String key, Exchange exchange) { if (optimistic) { throw new UnsupportedOperationException(); } LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key); Lock l = hzInstance.getLock(mapName); try { l.lock(); DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); DefaultExchangeHolder oldHolder = cache.put(key, newHolder); return unmarshallExchange(camelContext, oldHolder); } finally { LOG.trace("Added an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key); l.unlock(); } }
@Override public void remove(CamelContext camelContext, String key, Exchange exchange) { DefaultExchangeHolder holder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); if (optimistic) { LOG.trace("Removing an exchange with ID {} for key {} in an optimistic manner.", exchange.getExchangeId(), key); if (!cache.remove(key, holder)) { LOG.error("Optimistic locking failed for exchange with key {}: IMap#remove removed no Exchanges, while it's expected to remove one.", key); throw new OptimisticLockingException(); } LOG.trace("Removed an exchange with ID {} for key {} in an optimistic manner.", exchange.getExchangeId(), key); } else { cache.remove(key); } }
public static Object getIn(NettyEndpoint endpoint, Exchange exchange) { if (endpoint.getConfiguration().isTransferExchange()) { // we should transfer the entire exchange over the wire (includes in/out) return DefaultExchangeHolder.marshal(exchange, true, endpoint.getConfiguration().isAllowSerializedHeaders()); } else { if (endpoint.getConfiguration().isUseByteBuf()) { // Just leverage the type converter return exchange.getIn().getBody(ByteBuf.class); } else { // normal transfer using the body only return exchange.getIn().getBody(); } } }
@Override public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) { LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key); final DefaultExchangeHolder oldHolder = cache.getIfPresent(key); final DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); cache.put(key, newHolder); return unmarshallExchange(camelContext, oldHolder); }
@Override public Exchange add(CamelContext camelContext, String key, Exchange oldExchange, Exchange newExchange) throws OptimisticLockingException { if (!optimistic) { throw new UnsupportedOperationException(); } LOG.trace("Adding an Exchange with ID {} for key {} in an optimistic manner.", newExchange.getExchangeId(), key); if (oldExchange == null) { DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(newExchange, true, allowSerializedHeaders); DefaultExchangeHolder oldHolder = cache.getAndPut(key, newHolder); if (oldHolder != null) { Exchange exchange = unmarshallExchange(camelContext, oldHolder); LOG.error("Optimistic locking failed for exchange with key {}: IMap#putIfAbsend returned Exchange with ID {}, while it's expected no exchanges to be returned", key, exchange != null ? exchange.getExchangeId() : "<null>"); throw new OptimisticLockingException(); } } else { DefaultExchangeHolder oldHolder = DefaultExchangeHolder.marshal(oldExchange, true, allowSerializedHeaders); DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(newExchange, true, allowSerializedHeaders); if (!cache.replace(key, oldHolder, newHolder)) { LOG.error("Optimistic locking failed for exchange with key {}: IMap#replace returned no Exchanges, while it's expected to replace one", key); throw new OptimisticLockingException(); } } LOG.trace("Added an Exchange with ID {} for key {} in optimistic manner.", newExchange.getExchangeId(), key); return oldExchange; }
@Override public Exchange add(CamelContext camelContext, String key, Exchange oldExchange, Exchange newExchange) throws OptimisticLockingException { if (!optimistic) { throw new UnsupportedOperationException(); } LOG.trace("Adding an Exchange with ID {} for key {} in an optimistic manner.", newExchange.getExchangeId(), key); if (oldExchange == null) { DefaultExchangeHolder holder = DefaultExchangeHolder.marshal(newExchange, true, allowSerializedHeaders); final DefaultExchangeHolder misbehaviorHolder = cache.putIfAbsent(key, holder); if (misbehaviorHolder != null) { Exchange misbehaviorEx = unmarshallExchange(camelContext, misbehaviorHolder); LOG.error("Optimistic locking failed for exchange with key {}: IMap#putIfAbsend returned Exchange with ID {}, while it's expected no exchanges to be returned", key, misbehaviorEx != null ? misbehaviorEx.getExchangeId() : "<null>"); throw new OptimisticLockingException(); } } else { DefaultExchangeHolder oldHolder = DefaultExchangeHolder.marshal(oldExchange, true, allowSerializedHeaders); DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(newExchange, true, allowSerializedHeaders); if (!cache.replace(key, oldHolder, newHolder)) { LOG.error("Optimistic locking failed for exchange with key {}: IMap#replace returned no Exchanges, while it's expected to replace one", key); throw new OptimisticLockingException(); } } LOG.trace("Added an Exchange with ID {} for key {} in optimistic manner.", newExchange.getExchangeId(), key); return oldExchange; }
DefaultExchangeHolder holder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders); if (optimistic) { LOG.trace("Removing an exchange with ID {} for key {} in an optimistic manner.", exchange.getExchangeId(), key);
Serializable holder = DefaultExchangeHolder.marshal(exchange, true, endpoint.isAllowSerializedHeaders()); Message answer = session.createObjectMessage(holder);
public byte[] marshallExchange(CamelContext camelContext, Exchange exchange) throws IOException { // use DefaultExchangeHolder to marshal to a serialized object DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false); // add the aggregated size property as the only property we want to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class)); // add the aggregated completed by property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class)); // add the aggregated correlation key property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); // persist the from endpoint as well if (exchange.getFromEndpoint() != null) { DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri()); } return encode(pe); }
public ByteBuffer marshallExchange(CamelContext camelContext, Exchange exchange, boolean allowSerializedHeaders) throws IOException { // use DefaultExchangeHolder to marshal to a serialized object DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false, allowSerializedHeaders); // add the aggregated size and timeout property as the only properties we want to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class)); DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_TIMEOUT, exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, Long.class)); // add the aggregated completed by property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class)); // add the aggregated correlation key property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); // and a guard property if using the flexible toolbox aggregator DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COLLECTION_GUARD, exchange.getProperty(Exchange.AGGREGATED_COLLECTION_GUARD, String.class)); // persist the from endpoint as well if (exchange.getFromEndpoint() != null) { DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri()); } return ByteBuffer.wrap(serialize(pe)); }
public Buffer marshallExchange(CamelContext camelContext, Exchange exchange, boolean allowSerializedHeaders) throws IOException { DataByteArrayOutputStream baos = new DataByteArrayOutputStream(); // use DefaultExchangeHolder to marshal to a serialized object DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false, allowSerializedHeaders); // add the aggregated size and timeout property as the only properties we want to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class)); DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_TIMEOUT, exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, Long.class)); // add the aggregated completed by property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class)); // add the aggregated correlation key property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); // and a guard property if using the flexible toolbox aggregator DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COLLECTION_GUARD, exchange.getProperty(Exchange.AGGREGATED_COLLECTION_GUARD, String.class)); // persist the from endpoint as well if (exchange.getFromEndpoint() != null) { DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri()); } exchangeCodec.encode(pe, baos); return baos.toBuffer(); }
public byte[] marshallExchange(CamelContext camelContext, Exchange exchange, boolean allowSerializedHeaders) throws IOException { // use DefaultExchangeHolder to marshal to a serialized object DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false, allowSerializedHeaders); // add the aggregated size and timeout property as the only properties we want to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class)); DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_TIMEOUT, exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, Long.class)); // add the aggregated completed by property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class)); // add the aggregated correlation key property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); // and a guard property if using the flexible toolbox aggregator DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COLLECTION_GUARD, exchange.getProperty(Exchange.AGGREGATED_COLLECTION_GUARD, String.class)); // persist the from endpoint as well if (exchange.getFromEndpoint() != null) { DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri()); } return encode(pe); }