net.hasor.rsf.tconsole.InfoRsfInstruct Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed 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.rsf.tconsole;
import net.hasor.core.Inject;
import net.hasor.core.Singleton;
import net.hasor.rsf.InterAddress;
import net.hasor.rsf.RsfBindInfo;
import net.hasor.rsf.RsfContext;
import net.hasor.rsf.RsfSettings;
import net.hasor.rsf.domain.RsfServiceType;
import net.hasor.tconsole.TelCommand;
import net.hasor.tconsole.TelExecutor;
import java.io.StringWriter;
import java.util.*;
/**
* RSF框架工作信息。
* @version : 2016年4月3日
* @author 赵永春 ([email protected])
*/
@Singleton
public class InfoRsfInstruct implements TelExecutor {
@Inject
private RsfContext rsfContext;
@Override
public String helpInfo() {
return "show server info.\r\n"//
+ " - info -h (show help info.)\r\n"//
+ " - info (show server info.)";
}
@Override
public String doCommand(TelCommand telCommand) throws Throwable {
StringWriter sw = new StringWriter();
String[] args = telCommand.getCommandArgs();
if (args != null && args.length > 0) {
String doArg = args[0];
if ("-h".equalsIgnoreCase(doArg)) {
sw.write(helpInfo());
return sw.toString();
}
}
//
Set protocolSet = rsfContext.getSettings().getProtocos();
Map bindAddressSet = new HashMap<>();
for (String protocol : protocolSet) {
InterAddress interAddress = rsfContext.bindAddress(protocol);
if (interAddress != null) {
bindAddressSet.put(protocol, interAddress);
}
}
List arrays = new ArrayList<>(bindAddressSet.keySet());
Collections.sort(arrays);
RsfSettings settings = rsfContext.getSettings();
int providerCount = 0;
int customerCount = 0;
List serviceIDs = rsfContext.getServiceIDs();
for (String sid : serviceIDs) {
RsfBindInfo