/** * Creates a new channel. * * @param name See {@link #Channel(String, ExecutorService, Mode, InputStream, OutputStream, * OutputStream, boolean, ClassLoader)} * @param exec See {@link #Channel(String, ExecutorService, Mode, InputStream, OutputStream, * OutputStream, boolean, ClassLoader)} * @param transport The transport that we run {@link Channel} on top of. * @param base See {@link #Channel(String, ExecutorService, Mode, InputStream, OutputStream, * OutputStream, boolean, ClassLoader)} * @param restricted See {@link #Channel(String, ExecutorService, Mode, InputStream, OutputStream, * OutputStream, boolean, ClassLoader)} * @since 2.13 */ public Channel( String name, ExecutorService exec, CommandTransport transport, boolean restricted, ClassLoader base) throws IOException { this.name = name; this.executor = new InterceptingExecutorService(exec); this.isRestricted = restricted; this.underlyingOutput = transport.getUnderlyingStream(); if (base == null) base = getClass().getClassLoader(); this.baseClassLoader = base; if (export(this, false) != 1) throw new AssertionError(); // export number 1 is reserved for the channel itself remoteChannel = RemoteInvocationHandler.wrap(this, 1, IChannel.class, true, false); this.remoteCapability = transport.getRemoteCapability(); this.pipeWriter = new PipeWriter(createPipeWriterExecutor()); this.transport = transport; transport.setup( this, new CommandReceiver() { public void handle(Command cmd) { lastHeard = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Received " + cmd); try { cmd.execute(Channel.this); } catch (Throwable t) { logger.log( Level.SEVERE, "Failed to execute command " + cmd + " (channel " + Channel.this.name + ")", t); logger.log(Level.SEVERE, "This command is created here", cmd.createdAt); } } public void terminate(IOException e) { Channel.this.terminate(e); } }); }
/*package*/ Channel(ChannelBuilder settings, CommandTransport transport) throws IOException { this.name = settings.getName(); this.executor = new InterceptingExecutorService(settings.getExecutors()); this.isRestricted = settings.isRestricted(); this.underlyingOutput = transport.getUnderlyingStream(); this.jarCache = settings.getJarCache(); this.baseClassLoader = settings.getBaseLoader(); if (export(this, false) != 1) throw new AssertionError(); // export number 1 is reserved for the channel itself remoteChannel = RemoteInvocationHandler.wrap(this, 1, IChannel.class, true, false); this.remoteCapability = transport.getRemoteCapability(); this.pipeWriter = new PipeWriter(createPipeWriterExecutor()); this.transport = transport; this.jarLoader = new JarLoaderImpl(); // TODO: figure out a mechanism to allow the user to share this across // Channels setProperty(JarLoader.OURS, export(JarLoader.class, jarLoader, false)); transport.setup( this, new CommandReceiver() { public void handle(Command cmd) { lastHeard = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Received " + cmd); try { cmd.execute(Channel.this); } catch (Throwable t) { logger.log( Level.SEVERE, "Failed to execute command " + cmd + " (channel " + Channel.this.name + ")", t); logger.log(Level.SEVERE, "This command is created here", cmd.createdAt); } } public void terminate(IOException e) { Channel.this.terminate(e); } }); }