本文整理汇总了Java中com.alibaba.dubbo.common.utils.NetUtils.getLocalHost方法的典型用法代码示例。如果您正苦于以下问题:Java NetUtils.getLocalHost方法的具体用法?Java NetUtils.getLocalHost怎么用?Java NetUtils.getLocalHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.common.utils.NetUtils
的用法示例。
在下文中一共展示了NetUtils.getLocalHost方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: join
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public Peer join(URL url, ChannelHandler handler) throws RemotingException {
Peer peer = super.join(url, handler);
try {
String full = url.toFullString();
String[] lines = IOUtils.readLines(file);
for (String line : lines) {
if (full.equals(line)) {
return peer;
}
}
IOUtils.appendLines(file, new String[] {full});
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
return peer;
}
示例2: joinExchange
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public ExchangePeer joinExchange(URL url, ExchangeHandler handler) throws RemotingException {
ExchangePeer peer = super.join(url, handler);
try {
String full = url.toFullString();
String[] lines = IOUtils.readLines(file);
for (String line : lines) {
if (full.equals(line)) {
return peer;
}
}
IOUtils.appendLines(file, new String[] {full});
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
return peer;
}
示例3: leave
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
@Override
public void leave(URL url) throws RemotingException {
super.leave(url);
try {
String full = url.toFullString();
String[] lines = IOUtils.readLines(file);
List<String> saves = new ArrayList<String>();
for (String line : lines) {
if (full.equals(line)) {
return;
}
saves.add(line);
}
IOUtils.appendLines(file, saves.toArray(new String[0]));
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
}
示例4: index
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public void index(Map<String, Object> context) throws Exception {
Map<String, String> properties = new TreeMap<String, String>();
StringBuilder msg = new StringBuilder();
msg.append("Version: ");
msg.append(Version.getVersion(Envs.class, "2.2.0"));
properties.put("Registry", msg.toString());
String address = NetUtils.getLocalHost();
properties.put("Host", NetUtils.getHostName(address) + "/" + address);
properties.put("Java", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"));
properties.put("OS", System.getProperty("os.name") + " "
+ System.getProperty("os.version"));
properties.put("CPU", System.getProperty("os.arch", "") + ", "
+ String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores");
properties.put("Locale", Locale.getDefault().toString() + "/"
+ System.getProperty("file.encoding"));
properties.put("Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime())
+ " From " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime()))
+ " To " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date()));
context.put("properties", properties);
}
示例5: start
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public void start() {
String serverPort = ConfigUtils.getProperty(JETTY_PORT);
int port;
if (serverPort == null || serverPort.length() == 0) {
port = DEFAULT_JETTY_PORT;
} else {
port = Integer.parseInt(serverPort);
}
connector = new SelectChannelConnector();
connector.setPort(port);
ServletHandler handler = new ServletHandler();
String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
if (resources != null && resources.length() > 0) {
FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
resourceHolder.setInitParameter("resources", resources);
}
ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
pageHolder.setInitOrder(2);
Server server = new Server();
server.addConnector(connector);
server.addHandler(handler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
}
}
示例6: doInvoke
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
checkInvokers(invokers, invocation);
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
try {
return invoker.invoke(invocation);
} catch (Throwable e) {
if (e instanceof RpcException && ((RpcException)e).isBiz()) { // biz exception.
throw (RpcException) e;
}
throw new RpcException(e instanceof RpcException ? ((RpcException)e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e);
}
}
示例7: changed
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
private void changed() throws RemotingException {
try {
String[] lines = IOUtils.readLines(file);
for (String line : lines) {
connect(URL.valueOf(line));
}
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
}
示例8: doInvoke
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
checkInvokers(invokers, invocation);
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
try {
return invoker.invoke(invocation);
} catch (Throwable e) {
if (e instanceof RpcException && ((RpcException) e).isBiz()) { // biz exception.
throw (RpcException) e;
}
throw new RpcException(e instanceof RpcException ? ((RpcException) e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e);
}
}
示例9: getLocalHost
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
/**
* get local host.
*
* @return local host
*/
public String getLocalHost() {
String host = localAddress == null ? null :
localAddress.getAddress() == null ? localAddress.getHostName()
: NetUtils.filterLocalHost(localAddress.getAddress().getHostAddress());
if (host == null || host.length() == 0) {
return NetUtils.getLocalHost();
}
return host;
}
示例10: doList
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public List<Invoker<T>> doList(Invocation invocation) {
if (forbidden) {
throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "Forbid consumer " + NetUtils.getLocalHost() + " access service " + getInterface().getName() + " from registry " + getUrl().getAddress() + " use dubbo version " + Version.getVersion() + ", Please check registry access list (whitelist/blacklist).");
}
List<Invoker<T>> invokers = null;
Map<String, List<Invoker<T>>> localMethodInvokerMap = this.methodInvokerMap; // local reference
if (localMethodInvokerMap != null && localMethodInvokerMap.size() > 0) {
String methodName = RpcUtils.getMethodName(invocation);
Object[] args = RpcUtils.getArguments(invocation);
if(args != null && args.length > 0 && args[0] != null
&& (args[0] instanceof String || args[0].getClass().isEnum())) {
invokers = localMethodInvokerMap.get(methodName + "." + args[0]); // 可根据第一个参数枚举路由
}
if(invokers == null) {
invokers = localMethodInvokerMap.get(methodName);
}
if(invokers == null) {
invokers = localMethodInvokerMap.get(Constants.ANY_VALUE);
}
if(invokers == null) {
Iterator<List<Invoker<T>>> iterator = localMethodInvokerMap.values().iterator();
if (iterator.hasNext()) {
invokers = iterator.next();
}
}
}
return invokers == null ? new ArrayList<Invoker<T>>(0) : invokers;
}
示例11: doConnect
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
protected void doConnect() throws Throwable {
long start = System.currentTimeMillis();
ChannelFuture future = bootstrap.connect(getConnectAddress());
try{
boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS);
if (ret && future.isSuccess()) {
Channel newChannel = future.getChannel();
newChannel.setInterestOps(Channel.OP_READ_WRITE);
try {
// 关闭旧的连接
Channel oldChannel = NettyClient.this.channel; // copy reference
if (oldChannel != null) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel);
}
oldChannel.close();
} finally {
NettyChannel.removeChannelIfDisconnected(oldChannel);
}
}
} finally {
if (NettyClient.this.isClosed()) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close new netty channel " + newChannel + ", because the client closed.");
}
newChannel.close();
} finally {
NettyClient.this.channel = null;
NettyChannel.removeChannelIfDisconnected(newChannel);
}
} else {
NettyClient.this.channel = newChannel;
}
}
} else if (future.getCause() != null) {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause());
} else {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + " client-side timeout "
+ getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client "
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion());
}
}finally{
if (! isConnected()) {
future.cancel();
}
}
}
示例12: SimpleRegistryService
import com.alibaba.dubbo.common.utils.NetUtils; //导入方法依赖的package包/类
public SimpleRegistryService() {
super(new URL("dubbo", NetUtils.getLocalHost(), 0, RegistryService.class.getName(), "file", "N/A"));
}