protected void getStateFrom( JChannel channel, Protocol prot, String stack, String ch, DataOutputStream out) throws Exception { ByteArrayDataOutputStream output = new ByteArrayDataOutputStream(1024); OutputStreamAdapter out_ad = new OutputStreamAdapter(output); Event evt = new Event(Event.STATE_TRANSFER_OUTPUTSTREAM, out_ad); if (channel != null) channel.up(evt); else prot.up(evt); int len = output.position(); if (len > 0) { Bits.writeString(stack, out); Bits.writeString(ch, out); out.writeInt(len); out.write(output.buffer(), 0, len); log.trace("%s: fetched %d bytes from %s:%s", local_addr, len, stack, ch); } }
protected void setStateInMainAndForkChannels(InputStream in) { try (DataInputStream input = new DataInputStream(in)) { for (; ; ) { String stack_name = Bits.readString(input); String ch_name = Bits.readString(input); int len = input.readInt(); if (len > 0) { byte[] data = new byte[len]; in.read(data, 0, len); ByteArrayInputStream tmp = new ByteArrayInputStream(data, 0, len); if (stack_name == null && ch_name == null) up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp)); else { Protocol prot = fork_stacks.get(stack_name); if (prot == null) { log.warn( "%s: fork stack %s not found, dropping state for %s:%s", local_addr, stack_name, stack_name, ch_name); continue; } ForkProtocolStack fork_stack = getForkStack(prot); JChannel fork_ch = fork_stack.get(ch_name); if (fork_ch == null) { log.warn( "%s: fork channel %s not found, dropping state for %s:%s", local_addr, ch_name, stack_name, ch_name); continue; } fork_ch.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp)); } } } } catch (EOFException eof) { } catch (Throwable ex) { log.error("%s: failed setting state in main channel", local_addr, ex); } }