net.hasor.tconsole.client.TelnetClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hasor-tconsole Show documentation
Show all versions of hasor-tconsole Show documentation
The telnet console service for application.
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package net.hasor.tconsole.client;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import net.hasor.tconsole.CommandExecutor;
import net.hasor.utils.future.BasicFuture;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* simple telnet client.
*/
public final class TelnetClient {
public static void execCommand(String host, int port, final String command, Map envMap) throws Exception {
StringWriter commands = new StringWriter();
if (envMap != null) {
for (String key : envMap.keySet()) {
String val = envMap.get(key);
commands.write("set " + key + " = " + val + " \n");
}
}
commands.write("set " + CommandExecutor.AFTER_CLOSE_SESSION + " = true \n");
commands.write(command + "\n");
//
EventLoopGroup group = new NioEventLoopGroup();
final BasicFuture