/** * Creates a new AgentMBeanServerConnectionFactory * * @param builder The AgentMBeanServerConnectionFactory builder */ protected AgentMBeanServerConnectionFactory(Builder builder) { this.channel = builder.channel; this.remoteAddress = builder.remoteAddress == null ? this.channel.getRemoteAddress() : builder.remoteAddress; this.timeout = builder.timeout; this.listener = builder.listener; this.domain = builder.domain; if ("DefaultDomain".equals(domain)) { domainInfoData = new byte[] {0}; } else { byte[] domainBytes = domain.getBytes(); domainInfoData = new byte[domainBytes.length + 1]; domainInfoData[0] = (byte) domainBytes.length; System.arraycopy(domainBytes, 0, domainInfoData, 1, domainBytes.length); } if (channel.getPipeline().get(getClass().getSimpleName()) == null) { this.channel.getPipeline().addFirst(getClass().getSimpleName(), responseHandler); // LoggingHandler logg = new LoggingHandler(InternalLogLevel.ERROR, true); // this.channel.getPipeline().addFirst("logger", logg); } }
/** * Deserializes an array of arguments from a byte array * * @param bytes The byte array containing the serialized arguments * @return an object array */ public static Object[] getInput(byte[] bytes) { if (bytes.length == 0 || (bytes.length == 1 && bytes[0] == 0)) return new Object[0]; ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = null; GZIPInputStream gzis = null; Object[] args = null; try { gzis = new GZIPInputStream(bais); ois = new ObjectInputStream(gzis); Object obj = ois.readObject(); if (obj.getClass().isArray()) { args = new Object[Array.getLength(obj)]; System.arraycopy(obj, 0, args, 0, args.length); } else { args = new Object[] {obj}; } return args; } catch (Exception ex) { throw new RuntimeException("Failed to decode MBeanServerConnection Invocation arguments", ex); } finally { try { bais.close(); } catch (Exception ex) { /* No Op */ } if (ois != null) try { ois.close(); } catch (Exception ex) { /* No Op */ } if (gzis != null) try { gzis.close(); } catch (Exception ex) { /* No Op */ } } }