/** * Reads a {@link PackedInteger} value from the passed {@link DataInput input} and returns the * value of the integer. * * @param input The {@link DataInput} from which the {@link PackedInteger} value will be read * @return * @throws IOException * @throws IllegalArgumentException If the passed <code>input</code> is null */ public static int readPackedInteger(final DataInput input) throws IOException { int b = input.readByte(); if ((b & 0x80) == 0x80) { return readPackedInteger(input) << 7 | (b & 0x7F); } return b; }
/** * Converts the passed <code>value</code> into a {@link PackedInteger} and writes it to the * {@link DataOutput output} * * @param output The {@link DataOutput} to which the {@link PackedInteger} is written to * @param value The integer value which will be converted to a {@link PackedInteger} * @throws IOException * @throws IllegalArgumentException If the passed <code>value</code> is < 0. {@link PackedInteger} doesn't * allow signed integer * @throws IllegalArgumentException If the passed <code>output</code> is null */ public static void writePackedInteger(final DataOutput output, int value) throws IOException { if (value < 0) throw new IllegalArgumentException("Only unsigned integer can be packed"); if (value > 127) { output.writeByte(value & 0x7F | 0x80); writePackedInteger(output, value >> 7); } else { output.writeByte(value & 0xFF); } }
os.writeShort(invocation.getIndex()); final byte[] encoded = transactionID.getEncodedForm(); PackedInteger.writePackedInteger(os, encoded.length); os.write(encoded); if (withParam) { return flag ? PackedInteger.readPackedInteger(inputStream) : 0;
os.writeShort(invocation.getIndex()); final byte[] encoded = transactionID.getEncodedForm(); PackedInteger.writePackedInteger(os, encoded.length); os.write(encoded); if (withParam) { return flag ? PackedInteger.readPackedInteger(inputStream) : 0;
public void clusterRemoval(final List<String> clusterNames) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.CLUSTER_TOPOLOGY_REMOVAL); PackedInteger.writePackedInteger(os, clusterNames.size()); for (String clusterName : clusterNames) { os.writeUTF(clusterName); } } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB cluster message write failed", e); } }
ExceptionSupplier<ImportResult<?>, SystemException> readTransaction(final DataInput input) throws IOException { final int type = input.readUnsignedByte(); if (type == 0) { return null; } else if (type == 1) { // remote user transaction final int id = input.readInt(); final int timeout = PackedInteger.readPackedInteger(input); return () -> new ImportResult<Transaction>(transactionServer.getOrBeginTransaction(id, timeout), SubordinateTransactionControl.EMPTY, false); } else if (type == 2) { final int fmt = PackedInteger.readPackedInteger(input); final byte[] gtid = new byte[input.readUnsignedByte()]; input.readFully(gtid); final byte[] bq = new byte[input.readUnsignedByte()]; input.readFully(bq); final int timeout = PackedInteger.readPackedInteger(input); return () -> { try { return transactionServer.getTransactionService().getTransactionContext().findOrImportTransaction(new SimpleXid(fmt, gtid, bq), timeout); } catch (XAException e) { throw new SystemException(e.getMessage()); } }; } else { throw Logs.REMOTING.invalidTransactionType(type); } }
os.writeShort(invocation.getIndex()); final byte[] encoded = transactionID.getEncodedForm(); PackedInteger.writePackedInteger(os, encoded.length); os.write(encoded); if (withParam) { return flag ? PackedInteger.readPackedInteger(inputStream) : 0;
public void clusterNodesRemoved(final List<ClusterRemovalInfo> clusterRemovalInfoList) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.CLUSTER_TOPOLOGY_NODE_REMOVAL); PackedInteger.writePackedInteger(os, clusterRemovalInfoList.size()); for (ClusterRemovalInfo removalInfo : clusterRemovalInfoList) { os.writeUTF(removalInfo.getClusterName()); final List<String> nodeNamesList = removalInfo.getNodeNames(); PackedInteger.writePackedInteger(os, nodeNamesList.size()); for (String name : nodeNamesList) { os.writeUTF(name); } } } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB cluster message write failed", e); } } }
parameters[i] = unmarshaller.readObject(); int attachmentCount = PackedInteger.readPackedInteger(unmarshaller); final Map<String, Object> attachments = new HashMap<>(attachmentCount); for (int i = 0; i < attachmentCount; i ++) {
public void clusterNewNodesAdded(final ClusterInfo clusterInfo) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.CLUSTER_TOPOLOGY_ADDITION); PackedInteger.writePackedInteger(os, 1); os.writeUTF(clusterInfo.getClusterName()); final List<NodeInfo> nodeInfoList = clusterInfo.getNodeInfoList(); PackedInteger.writePackedInteger(os, nodeInfoList.size()); for (NodeInfo nodeInfo : nodeInfoList) { os.writeUTF(nodeInfo.getNodeName()); final List<MappingInfo> mappingInfoList = nodeInfo.getMappingInfoList(); PackedInteger.writePackedInteger(os, mappingInfoList.size()); for (MappingInfo mappingInfo : mappingInfoList) { boolean is6 = mappingInfo.getSourceAddress() instanceof Inet6Address; if (is6) { PackedInteger.writePackedInteger(os, mappingInfo.getNetmaskBits() << 1); } else { PackedInteger.writePackedInteger(os, mappingInfo.getNetmaskBits() << 1 | 1); } os.write(mappingInfo.getSourceAddress().getAddress()); os.writeUTF(mappingInfo.getDestinationAddress()); os.writeShort(mappingInfo.getDestinationPort()); } } } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB cluster message write failed", e); } }
byte[] encoded = new byte[PackedInteger.readPackedInteger(inputStream)]; inputStream.readFully(encoded); final SessionID sessionID = SessionID.createSessionID(encoded); byte[] b = new byte[PackedInteger.readPackedInteger(inputStream)]; inputStream.readFully(b); context.setWeakAffinity(new NodeAffinity(new String(b, StandardCharsets.UTF_8))); byte[] b = new byte[PackedInteger.readPackedInteger(inputStream)]; inputStream.readFully(b); context.setLocator(context.getLocator().withNewAffinity(new ClusterAffinity(new String(b, StandardCharsets.UTF_8))));
public void clusterTopology(final List<ClusterInfo> clusterInfoList) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.CLUSTER_TOPOLOGY_COMPLETE); PackedInteger.writePackedInteger(os, clusterInfoList.size()); for (ClusterInfo clusterInfo : clusterInfoList) { os.writeUTF(clusterInfo.getClusterName()); final List<NodeInfo> nodeInfoList = clusterInfo.getNodeInfoList(); PackedInteger.writePackedInteger(os, nodeInfoList.size()); for (NodeInfo nodeInfo : nodeInfoList) { os.writeUTF(nodeInfo.getNodeName()); final List<MappingInfo> mappingInfoList = nodeInfo.getMappingInfoList(); PackedInteger.writePackedInteger(os, mappingInfoList.size()); for (MappingInfo mappingInfo : mappingInfoList) { boolean is6 = mappingInfo.getSourceAddress() instanceof Inet6Address; if (is6) { PackedInteger.writePackedInteger(os, mappingInfo.getNetmaskBits() << 1); } else { PackedInteger.writePackedInteger(os, mappingInfo.getNetmaskBits() << 1 | 1); } os.write(mappingInfo.getSourceAddress().getAddress()); os.writeUTF(mappingInfo.getDestinationAddress()); os.writeShort(mappingInfo.getDestinationPort()); } } } } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB cluster message write failed", e); } }
case Protocol.OPEN_SESSION_RESPONSE: { Affinity affinity; int size = PackedInteger.readPackedInteger(response); byte[] bytes = new byte[size]; response.readFully(bytes); final byte[] b = new byte[PackedInteger.readPackedInteger(response)]; response.readFully(b); clientInvocationContext.setWeakAffinity(new NodeAffinity(new String(b, StandardCharsets.UTF_8))); final byte[] b = new byte[PackedInteger.readPackedInteger(response)]; response.readFully(b); String clusterName = new String(b, StandardCharsets.UTF_8);
private void writeTxnResponse(final int invId, final int flag) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.TXN_RESPONSE); os.writeShort(invId); os.writeBoolean(true); PackedInteger.writePackedInteger(os, flag); } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB transaction response write failed", e); } }
private void handleTxnRequest(final int code, final int invId, final MessageInputStream message) throws IOException { final byte[] bytes = new byte[PackedInteger.readPackedInteger(message)]; message.readFully(bytes); final TransactionID transactionID = TransactionID.createTransactionID(bytes);
int transactionTimeout = remoteTransaction.getEstimatedRemainingTime(); if(transactionTimeout == 0) throw Logs.TXN.outflowTransactionTimeoutElapsed(transaction); PackedInteger.writePackedInteger(dataOutput, transactionTimeout); return null; } else if (transaction instanceof LocalTransaction) { final Xid xid = outflowHandle.getXid(); dataOutput.writeByte(2); PackedInteger.writePackedInteger(dataOutput, xid.getFormatId()); final byte[] gtid = xid.getGlobalTransactionId(); dataOutput.writeByte(gtid.length); int transactionTimeout = outflowHandle.getRemainingTime(); if(transactionTimeout == 0) throw Logs.TXN.outflowTransactionTimeoutElapsed(transaction); PackedInteger.writePackedInteger(dataOutput, transactionTimeout); return outflowHandle; } else {
/** * Reads a {@link PackedInteger} value from the passed {@link DataInput input} and returns the * value of the integer. * * @param input The {@link DataInput} from which the {@link PackedInteger} value will be read * @return * @throws IOException * @throws IllegalArgumentException If the passed <code>input</code> is null */ public static int readPackedInteger(final DataInput input) throws IOException { int b = input.readByte(); if ((b & 0x80) == 0x80) { return readPackedInteger(input) << 7 | (b & 0x7F); } return b; }
if (sessionId != null) { final byte[] bytes = sessionId.getEncodedForm(); PackedInteger.writePackedInteger(os, bytes.length); os.write(bytes); final String nodeName = weakAffinityUpdate.getNodeName(); final byte[] bytes = nodeName.getBytes(StandardCharsets.UTF_8); PackedInteger.writePackedInteger(os, bytes.length); os.write(bytes); final String clusterName = strongAffinityUpdate.getClusterName(); final byte[] bytes = clusterName.getBytes(StandardCharsets.UTF_8); PackedInteger.writePackedInteger(os, bytes.length); os.write(bytes);
/** * Reads a {@link PackedInteger} value from the passed {@link DataInput input} and returns the * value of the integer. * * @param input The {@link DataInput} from which the {@link PackedInteger} value will be read * @return * @throws IOException * @throws IllegalArgumentException If the passed <code>input</code> is null */ public static int readPackedInteger(final DataInput input) throws IOException { int b = input.readByte(); if ((b & 0x80) == 0x80) { return readPackedInteger(input) << 7 | (b & 0x7F); } return b; }
private void doWrite(final boolean available, final List<EJBModuleIdentifier> modules) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(available ? Protocol.MODULE_AVAILABLE : Protocol.MODULE_UNAVAILABLE); PackedInteger.writePackedInteger(os, modules.size()); for (EJBModuleIdentifier module : modules) { final String appName = module.getAppName(); os.writeUTF(appName == null ? "" : appName); final String moduleName = module.getModuleName(); os.writeUTF(moduleName == null ? "" : moduleName); final String distinctName = module.getDistinctName(); os.writeUTF(distinctName == null ? "" : distinctName); } } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB availability message write failed", e); } } }