overrides, prefer to use our utils methods

This commit is contained in:
Vladimir Krivosheev
2013-12-23 18:03:12 +01:00
parent 668b0c1585
commit 558b4bac4b
5 changed files with 19 additions and 24 deletions
@@ -17,13 +17,13 @@ package com.intellij.execution.runners;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.openapi.util.Key;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NonNls;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
@@ -37,7 +37,6 @@ class ProcessProxyImpl implements ProcessProxy {
@NonNls public static final String PROPERTY_PORT_NUMBER = "idea.launcher.port";
@NonNls public static final String LAUNCH_MAIN_CLASS = "com.intellij.rt.execution.application.AppMain";
@NonNls protected static final String LOCALHOST = "localhost";
@NonNls private static final String DONT_USE_LAUNCHER_PROPERTY = "idea.no.launcher";
private static final int SOCKET_NUMBER_START = 7532;
private static final int SOCKET_NUMBER = 100;
@@ -71,10 +70,12 @@ class ProcessProxyImpl implements ProcessProxy {
return -1;
}
@Override
public int getPortNumber() {
return myPortNumber;
}
@Override
@SuppressWarnings("FinalizeDeclaration")
protected synchronized void finalize() throws Throwable {
if (myWriter != null) {
@@ -84,6 +85,7 @@ class ProcessProxyImpl implements ProcessProxy {
super.finalize();
}
@Override
public void attach(final ProcessHandler processHandler) {
processHandler.putUserData(KEY, this);
}
@@ -93,7 +95,7 @@ class ProcessProxyImpl implements ProcessProxy {
if (myWriter == null) {
try {
if (mySocket == null) {
mySocket = new Socket(InetAddress.getByName(LOCALHOST), myPortNumber);
mySocket = new Socket(NetUtils.getLoopbackAddress(), myPortNumber);
}
myWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mySocket.getOutputStream())));
}
@@ -105,10 +107,12 @@ class ProcessProxyImpl implements ProcessProxy {
myWriter.flush();
}
@Override
public void sendBreak() {
writeLine("BREAK");
}
@Override
public void sendStop() {
writeLine("STOP");
}
@@ -29,9 +29,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
/**
* @author yole
*/
public class NetUtils {
private static final Logger LOG = Logger.getInstance(NetUtils.class);
@@ -18,6 +18,7 @@ package com.intellij.util.io.socketConnection.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.io.socketConnection.*;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -71,7 +72,7 @@ public class SocketConnectionImpl<Request extends AbstractRequest, Response exte
host = InetAddress.getLocalHost();
}
catch (UnknownHostException ignored) {
host = InetAddress.getByName(null);
host = NetUtils.getLoopbackAddress();
}
}
@@ -1,17 +1,12 @@
package com.jetbrains.python.console.pydev;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.net.NetUtils;
import org.apache.xmlrpc.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Vector;
/**
@@ -25,12 +20,12 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient {
/**
* Internal xml-rpc client (responsible for the actual communication with the server)
*/
private XmlRpcClient impl;
private final XmlRpcClient impl;
/**
* The process where the server is being executed.
*/
private Process process;
private final Process process;
/**
* ItelliJ Logging
@@ -43,15 +38,9 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient {
/**
* Constructor (see fields description)
*/
public PydevXmlRpcClient(Process process, int port)
throws MalformedURLException {
String hostname = NetUtils.getLocalHostString();
URL url = new URL("http://" + hostname + ':' + port + "/RPC2");
XmlRpc.setDefaultInputEncoding("UTF8"); //eventhough it uses UTF anyway
this.impl = new XmlRpcClientLite(url);
public PydevXmlRpcClient(Process process, int port) throws MalformedURLException {
XmlRpc.setDefaultInputEncoding("UTF8"); //even though it uses UTF anyway
impl = new XmlRpcClientLite(NetUtils.getLocalHostString(), port);
//this.impl = new XmlRpcClient(url, new CommonsXmlRpcTransportFactory(url));
this.process = process;
}
@@ -64,16 +53,19 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient {
*
* @return the result from executing the given command in the server.
*/
@Override
public Object execute(String command, Object[] args) throws XmlRpcException {
final Object[] result = new Object[]{null};
//make an async call so that we can keep track of not actually having an answer.
this.impl.executeAsync(command, new Vector(Arrays.asList(args)), new AsyncCallback() {
impl.executeAsync(command, new Vector(Arrays.asList(args)), new AsyncCallback() {
@Override
public void handleError(Exception error, URL url, String method) {
result[0] = new Object[]{error.getMessage()};
}
@Override
public void handleResult(Object recievedResult, URL url, String method) {
result[0] = recievedResult;
}
@@ -38,6 +38,7 @@ import java.util.List;
public class DefaultUrlOpener extends UrlOpener {
private static final Logger LOG = Logger.getInstance(DefaultUrlOpener.class);
@Override
public boolean openUrl(final @NotNull WebBrowser browser, final @NotNull String url) {
return launchBrowser(browser, url, false);
}