code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
@Override public List<Integer> loadAllDataFromCache() throws CacheLoadingException { ArrayList<Integer> listData = new ArrayList<Integer>(); listData.add(STUB_DATA); return listData; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
loadAllDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
@Override public List<Object> getAllCacheKeys() { return new ArrayList<Object>(); }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
getAllCacheKeys
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
@Override public Integer saveDataToCacheAndReturnData(Integer data, Object cacheKey) throws CacheSavingException { return data; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
saveDataToCacheAndReturnData
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
@Override public boolean removeDataFromCache(Object cacheKey) { return true; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
removeDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
@Override public void removeAllDataFromCache() { }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
removeAllDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
@Override public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException { return 0; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
getCreationDateInCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
@Override public boolean isDataInCache(Object cacheKey, long maxTimeInCache) { return maxTimeInCache != DurationInMillis.ALWAYS_EXPIRED && maxTimeInCache < DurationInMillis.ONE_MINUTE; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
isDataInCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/IntegerPersisterStub.java
Apache-2.0
protected void signalStopWaiting() { lock.lock(); try { requestFinishedCondition.signal(); } finally { lock.unlock(); } }
Indicates whether or not request can be considered as finished.
signalStopWaiting
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/SpiceRequestStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/SpiceRequestStub.java
Apache-2.0
public boolean isLoadDataFromNetworkCalled() { signalStopWaiting(); return isLoadDataFromNetworkCalled; }
@return a boolean to indicate whether or not the {@link #loadDataFromNetwork()} method has been called.
isLoadDataFromNetworkCalled
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/SpiceRequestStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/SpiceRequestStub.java
Apache-2.0
public void awaitForLoadDataFromNetworkIsCalled(long millisecond) throws InterruptedException { if (isLoadDataFromNetworkCalled) { return; } lock.lock(); try { requestFinishedCondition.await(millisecond, TimeUnit.MILLISECONDS); } finally { lock.unlock(); } }
@return a boolean to indicate whether or not the {@link #loadDataFromNetwork()} method has been called.
awaitForLoadDataFromNetworkIsCalled
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/SpiceRequestStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/SpiceRequestStub.java
Apache-2.0
@Override public String loadDataFromCache(Object cacheKey, long maxTimeInCache) throws CacheLoadingException { return null; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
loadDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public List<String> loadAllDataFromCache() throws CacheLoadingException { return new ArrayList<String>(); }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
loadAllDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public List<Object> getAllCacheKeys() { return new ArrayList<Object>(); }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
getAllCacheKeys
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public String saveDataToCacheAndReturnData(String data, Object cacheKey) throws CacheSavingException { return data; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
saveDataToCacheAndReturnData
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public boolean removeDataFromCache(Object cacheKey) { return true; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
removeDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public void removeAllDataFromCache() { }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
removeAllDataFromCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException { throw new CacheLoadingException("This persisters stores no data."); }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
getCreationDateInCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public boolean isDataInCache(Object cacheKey, long maxTimeInCache) { return false; }
Stub of an object persister. Doesn't use any real cache management. Will help to pass the tests without any side-effect. @author sni
isDataInCache
java
stephanenicolas/robospice
robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice-core-test/src/main/java/com/octo/android/robospice/stub/StringPersisterStub.java
Apache-2.0
@Override public void run() { try { bind(inst, agentLoader, agentArgs); } catch (Throwable throwable) { throwable.printStackTrace(ps); } }
Use a dedicated thread to run the binding logic to prevent possible memory leak. #195
run
java
alibaba/arthas
agent/src/main/java/com/taobao/arthas/agent334/AgentBootstrap.java
https://github.com/alibaba/arthas/blob/master/agent/src/main/java/com/taobao/arthas/agent334/AgentBootstrap.java
Apache-2.0
private static void bind(Instrumentation inst, ClassLoader agentLoader, String args) throws Throwable { /** * <pre> * ArthasBootstrap bootstrap = ArthasBootstrap.getInstance(inst); * </pre> */ Class<?> bootstrapClass = agentLoader.loadClass(ARTHAS_BOOTSTRAP); Object bootstrap = bootstrapClass.getMethod(GET_INSTANCE, Instrumentation.class, String.class).invoke(null, inst, args); boolean isBind = (Boolean) bootstrapClass.getMethod(IS_BIND).invoke(bootstrap); if (!isBind) { String errorMsg = "Arthas server port binding failed! Please check $HOME/logs/arthas/arthas.log for more details."; ps.println(errorMsg); throw new RuntimeException(errorMsg); } ps.println("Arthas server already bind."); }
<pre> ArthasBootstrap bootstrap = ArthasBootstrap.getInstance(inst); </pre>
bind
java
alibaba/arthas
agent/src/main/java/com/taobao/arthas/agent334/AgentBootstrap.java
https://github.com/alibaba/arthas/blob/master/agent/src/main/java/com/taobao/arthas/agent334/AgentBootstrap.java
Apache-2.0
private static String decodeArg(String arg) { try { return URLDecoder.decode(arg, "utf-8"); } catch (UnsupportedEncodingException e) { return arg; } }
<pre> ArthasBootstrap bootstrap = ArthasBootstrap.getInstance(inst); </pre>
decodeArg
java
alibaba/arthas
agent/src/main/java/com/taobao/arthas/agent334/AgentBootstrap.java
https://github.com/alibaba/arthas/blob/master/agent/src/main/java/com/taobao/arthas/agent334/AgentBootstrap.java
Apache-2.0
public static void attach(Map<String, String> configMap) { new ArthasAgent(configMap).init(); }
@see https://arthas.aliyun.com/doc/arthas-properties.html @param configMap
attach
java
alibaba/arthas
arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
https://github.com/alibaba/arthas/blob/master/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
Apache-2.0
public static void attach(String arthasHome) { new ArthasAgent(arthasHome).init(); }
use the specified arthas @param arthasHome arthas directory
attach
java
alibaba/arthas
arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
https://github.com/alibaba/arthas/blob/master/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
Apache-2.0
private static File createTempDir() { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseName = "arthas-" + System.currentTimeMillis() + "-"; for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')'); }
<pre> ArthasBootstrap bootstrap = ArthasBootstrap.getInstance(inst); </pre>
createTempDir
java
alibaba/arthas
arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
https://github.com/alibaba/arthas/blob/master/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
Apache-2.0
public String getErrorMessage() { return errorMessage; }
<pre> ArthasBootstrap bootstrap = ArthasBootstrap.getInstance(inst); </pre>
getErrorMessage
java
alibaba/arthas
arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
https://github.com/alibaba/arthas/blob/master/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
Apache-2.0
public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
<pre> ArthasBootstrap bootstrap = ArthasBootstrap.getInstance(inst); </pre>
setErrorMessage
java
alibaba/arthas
arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
https://github.com/alibaba/arthas/blob/master/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java
Apache-2.0
@Argument(argName = "pid", index = 0, required = false) @Description("Target pid") public void setPid(long pid) { this.pid = pid; }
enforce use http to download arthas. default use https
setPid
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(shortName = "h", longName = "help", flag = true) @Description("Print usage") public void setHelp(boolean help) { this.help = help; }
enforce use http to download arthas. default use https
setHelp
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "target-ip") @Description("The target jvm listen ip, default 127.0.0.1") public void setTargetIp(String targetIp) { this.targetIp = targetIp; }
enforce use http to download arthas. default use https
setTargetIp
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "telnet-port") @Description("The target jvm listen telnet port, default 3658") public void setTelnetPort(int telnetPort) { this.telnetPort = telnetPort; }
enforce use http to download arthas. default use https
setTelnetPort
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "http-port") @Description("The target jvm listen http port, default 8563") public void setHttpPort(int httpPort) { this.httpPort = httpPort; }
enforce use http to download arthas. default use https
setHttpPort
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "session-timeout") @Description("The session timeout seconds, default 1800 (30min)") public void setSessionTimeout(Long sessionTimeout) { this.sessionTimeout = sessionTimeout; }
enforce use http to download arthas. default use https
setSessionTimeout
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "arthas-home") @Description("The arthas home") public void setArthasHome(String arthasHome) { this.arthasHome = arthasHome; }
enforce use http to download arthas. default use https
setArthasHome
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "use-version") @Description("Use special version arthas") public void setUseVersion(String useVersion) { this.useVersion = useVersion; }
enforce use http to download arthas. default use https
setUseVersion
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "repo-mirror") @Description("Use special remote repository mirror, value is center/aliyun or http repo url.") public void setRepoMirror(String repoMirror) { this.repoMirror = repoMirror; }
enforce use http to download arthas. default use https
setRepoMirror
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "versions", flag = true) @Description("List local and remote arthas versions") public void setVersions(boolean versions) { this.versions = versions; }
enforce use http to download arthas. default use https
setVersions
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "use-http", flag = true) @Description("Enforce use http to download, default use https") public void setuseHttp(boolean useHttp) { this.useHttp = useHttp; }
enforce use http to download arthas. default use https
setuseHttp
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "attach-only", flag = true) @Description("Attach target process only, do not connect") public void setAttachOnly(boolean attachOnly) { this.attachOnly = attachOnly; }
enforce use http to download arthas. default use https
setAttachOnly
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(shortName = "c", longName = "command") @Description("Command to execute, multiple commands separated by ;") public void setCommand(String command) { this.command = command; }
enforce use http to download arthas. default use https
setCommand
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(shortName = "f", longName = "batch-file") @Description("The batch file to execute") public void setBatchFile(String batchFile) { this.batchFile = batchFile; }
enforce use http to download arthas. default use https
setBatchFile
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "height") @Description("arthas-client terminal height") public void setHeight(int height) { this.height = height; }
enforce use http to download arthas. default use https
setHeight
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "width") @Description("arthas-client terminal width") public void setWidth(int width) { this.width = width; }
enforce use http to download arthas. default use https
setWidth
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(shortName = "v", longName = "verbose", flag = true) @Description("Verbose, print debug info.") public void setVerbose(boolean verbose) { this.verbose = verbose; }
enforce use http to download arthas. default use https
setVerbose
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "tunnel-server") @Description("The tunnel server url") public void setTunnelServer(String tunnelServer) { this.tunnelServer = tunnelServer; }
enforce use http to download arthas. default use https
setTunnelServer
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "agent-id") @Description("The agent id register to tunnel server") public void setAgentId(String agentId) { this.agentId = agentId; }
enforce use http to download arthas. default use https
setAgentId
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "app-name") @Description("The app name") public void setAppName(String appName) { this.appName = appName; }
enforce use http to download arthas. default use https
setAppName
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "username") @Description("The username") public void setUsername(String username) { this.username = username; }
enforce use http to download arthas. default use https
setUsername
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "password") @Description("The password") public void setPassword(String password) { this.password = password; }
enforce use http to download arthas. default use https
setPassword
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "stat-url") @Description("The report stat url") public void setStatUrl(String statUrl) { this.statUrl = statUrl; }
enforce use http to download arthas. default use https
setStatUrl
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "select") @Description("select target process by classname or JARfilename") public void setSelect(String select) { this.select = select; }
enforce use http to download arthas. default use https
setSelect
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
@Option(longName = "disabled-commands") @Description("disable some commands ") public void setDisabledCommands(String disabledCommands) { this.disabledCommands = disabledCommands; }
enforce use http to download arthas. default use https
setDisabledCommands
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { String javaHome = System.getProperty("java.home"); if (javaHome != null) { AnsiLog.info("JAVA_HOME: " + javaHome); } Package bootstrapPackage = Bootstrap.class.getPackage(); if (bootstrapPackage != null) { String arthasBootVersion = bootstrapPackage.getImplementationVersion(); if (arthasBootVersion != null) { AnsiLog.info("arthas-boot version: " + arthasBootVersion); } } try { String javaToolOptions = System.getenv("JAVA_TOOL_OPTIONS"); if (javaToolOptions != null && !javaToolOptions.trim().isEmpty()) { AnsiLog.info("JAVA_TOOL_OPTIONS: " + javaToolOptions); } } catch (Throwable e) { // ignore } Bootstrap bootstrap = new Bootstrap(); CLI cli = CLIConfigurator.define(Bootstrap.class); CommandLine commandLine = cli.parse(Arrays.asList(args)); try { CLIConfigurator.inject(commandLine, bootstrap); } catch (Throwable e) { e.printStackTrace(); System.out.println(usage(cli)); System.exit(1); } if (bootstrap.isVerbose()) { AnsiLog.level(Level.ALL); } if (bootstrap.isHelp()) { System.out.println(usage(cli)); System.exit(0); } if (bootstrap.getRepoMirror() == null || bootstrap.getRepoMirror().trim().isEmpty()) { bootstrap.setRepoMirror("center"); // if timezone is +0800, default repo mirror is aliyun if (TimeUnit.MILLISECONDS.toHours(TimeZone.getDefault().getOffset(System.currentTimeMillis())) == 8) { bootstrap.setRepoMirror("aliyun"); } } AnsiLog.debug("Repo mirror:" + bootstrap.getRepoMirror()); if (bootstrap.isVersions()) { System.out.println(UsageRender.render(listVersions())); System.exit(0); } if (JavaVersionUtils.isJava6() || JavaVersionUtils.isJava7()) { bootstrap.setuseHttp(true); AnsiLog.debug("Java version is {}, only support http, set useHttp to true.", JavaVersionUtils.javaVersionStr()); } // check telnet/http port long telnetPortPid = -1; long httpPortPid = -1; if (bootstrap.getTelnetPortOrDefault() > 0) { telnetPortPid = SocketUtils.findTcpListenProcess(bootstrap.getTelnetPortOrDefault()); if (telnetPortPid > 0) { AnsiLog.info("Process {} already using port {}", telnetPortPid, bootstrap.getTelnetPortOrDefault()); } } if (bootstrap.getHttpPortOrDefault() > 0) { httpPortPid = SocketUtils.findTcpListenProcess(bootstrap.getHttpPortOrDefault()); if (httpPortPid > 0) { AnsiLog.info("Process {} already using port {}", httpPortPid, bootstrap.getHttpPortOrDefault()); } } long pid = bootstrap.getPid(); // select pid if (pid < 0) { try { pid = ProcessUtils.select(bootstrap.isVerbose(), telnetPortPid, bootstrap.getSelect()); } catch (InputMismatchException e) { System.out.println("Please input an integer to select pid."); System.exit(1); } if (pid < 0) { System.out.println("Please select an available pid."); System.exit(1); } } checkTelnetPortPid(bootstrap, telnetPortPid, pid); if (httpPortPid > 0 && pid != httpPortPid) { AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.", pid, bootstrap.getHttpPortOrDefault()); AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it first with running the 'stop' command.", httpPortPid); AnsiLog.error("2. Or try to use different http port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port 9999"); System.exit(1); } // find arthas home File arthasHomeDir = null; if (bootstrap.getArthasHome() != null) { verifyArthasHome(bootstrap.getArthasHome()); arthasHomeDir = new File(bootstrap.getArthasHome()); } if (arthasHomeDir == null && bootstrap.getUseVersion() != null) { // try to find from ~/.arthas/lib File specialVersionDir = new File(System.getProperty("user.home"), ".arthas" + File.separator + "lib" + File.separator + bootstrap.getUseVersion() + File.separator + "arthas"); if (!specialVersionDir.exists()) { // try to download arthas from remote server. DownloadUtils.downArthasPackaging(bootstrap.getRepoMirror(), bootstrap.isUseHttp(), bootstrap.getUseVersion(), ARTHAS_LIB_DIR.getAbsolutePath()); } verifyArthasHome(specialVersionDir.getAbsolutePath()); arthasHomeDir = specialVersionDir; } // Try set the directory where arthas-boot.jar is located to arthas home if (arthasHomeDir == null) { CodeSource codeSource = Bootstrap.class.getProtectionDomain().getCodeSource(); if (codeSource != null) { try { // https://stackoverflow.com/a/17870390 File bootJarPath = new File(codeSource.getLocation().toURI().getSchemeSpecificPart()); verifyArthasHome(bootJarPath.getParent()); arthasHomeDir = bootJarPath.getParentFile(); } catch (Throwable e) { // ignore } } } // try to download from remote server if (arthasHomeDir == null) { boolean checkFile = ARTHAS_LIB_DIR.exists() || ARTHAS_LIB_DIR.mkdirs(); if(!checkFile){ AnsiLog.error("cannot create directory {}: maybe permission denied", ARTHAS_LIB_DIR.getAbsolutePath()); System.exit(1); } /** * <pre> * 1. get local latest version * 2. get remote latest version * 3. compare two version * </pre> */ List<String> versionList = listNames(ARTHAS_LIB_DIR); Collections.sort(versionList); String localLatestVersion = null; if (!versionList.isEmpty()) { localLatestVersion = versionList.get(versionList.size() - 1); } String remoteLatestVersion = DownloadUtils.readLatestReleaseVersion(); boolean needDownload = false; if (localLatestVersion == null) { if (remoteLatestVersion == null) { // exit AnsiLog.error("Can not find Arthas under local: {} and remote repo mirror: {}", ARTHAS_LIB_DIR, bootstrap.getRepoMirror()); AnsiLog.error( "Unable to download arthas from remote server, please download the full package according to wiki: https://github.com/alibaba/arthas"); System.exit(1); } else { needDownload = true; } } else { if (remoteLatestVersion != null) { if (localLatestVersion.compareTo(remoteLatestVersion) < 0) { AnsiLog.info("local latest version: {}, remote latest version: {}, try to download from remote.", localLatestVersion, remoteLatestVersion); needDownload = true; } } } if (needDownload) { // try to download arthas from remote server. DownloadUtils.downArthasPackaging(bootstrap.getRepoMirror(), bootstrap.isUseHttp(), remoteLatestVersion, ARTHAS_LIB_DIR.getAbsolutePath()); localLatestVersion = remoteLatestVersion; } // get the latest version arthasHomeDir = new File(ARTHAS_LIB_DIR, localLatestVersion + File.separator + "arthas"); } verifyArthasHome(arthasHomeDir.getAbsolutePath()); AnsiLog.info("arthas home: " + arthasHomeDir); if (telnetPortPid > 0 && pid == telnetPortPid) { AnsiLog.info("The target process already listen port {}, skip attach.", bootstrap.getTelnetPortOrDefault()); } else { //double check telnet port and pid before attach telnetPortPid = findProcessByTelnetClient(arthasHomeDir.getAbsolutePath(), bootstrap.getTelnetPortOrDefault()); checkTelnetPortPid(bootstrap, telnetPortPid, pid); if (telnetPortPid > 0 && pid == telnetPortPid) { AnsiLog.info("The target process already listen port {}, skip attach.", bootstrap.getTelnetPortOrDefault()); } else { // start arthas-core.jar List<String> attachArgs = new ArrayList<String>(); attachArgs.add("-jar"); attachArgs.add(new File(arthasHomeDir, "arthas-core.jar").getAbsolutePath()); attachArgs.add("-pid"); attachArgs.add("" + pid); if (bootstrap.getTargetIp() != null) { attachArgs.add("-target-ip"); attachArgs.add(bootstrap.getTargetIp()); } if (bootstrap.getTelnetPort() != null) { attachArgs.add("-telnet-port"); attachArgs.add("" + bootstrap.getTelnetPort()); } if (bootstrap.getHttpPort() != null) { attachArgs.add("-http-port"); attachArgs.add("" + bootstrap.getHttpPort()); } attachArgs.add("-core"); attachArgs.add(new File(arthasHomeDir, "arthas-core.jar").getAbsolutePath()); attachArgs.add("-agent"); attachArgs.add(new File(arthasHomeDir, "arthas-agent.jar").getAbsolutePath()); if (bootstrap.getSessionTimeout() != null) { attachArgs.add("-session-timeout"); attachArgs.add("" + bootstrap.getSessionTimeout()); } if (bootstrap.getAppName() != null) { attachArgs.add("-app-name"); attachArgs.add(bootstrap.getAppName()); } if (bootstrap.getUsername() != null) { attachArgs.add("-username"); attachArgs.add(bootstrap.getUsername()); } if (bootstrap.getPassword() != null) { attachArgs.add("-password"); attachArgs.add(bootstrap.getPassword()); } if (bootstrap.getTunnelServer() != null) { attachArgs.add("-tunnel-server"); attachArgs.add(bootstrap.getTunnelServer()); } if (bootstrap.getAgentId() != null) { attachArgs.add("-agent-id"); attachArgs.add(bootstrap.getAgentId()); } if (bootstrap.getStatUrl() != null) { attachArgs.add("-stat-url"); attachArgs.add(bootstrap.getStatUrl()); } if (bootstrap.getDisabledCommands() != null) { attachArgs.add("-disabled-commands"); attachArgs.add(bootstrap.getDisabledCommands()); } AnsiLog.info("Try to attach process " + pid); AnsiLog.debug("Start arthas-core.jar args: " + attachArgs); ProcessUtils.startArthasCore(pid, attachArgs); AnsiLog.info("Attach process {} success.", pid); } } if (bootstrap.isAttachOnly()) { System.exit(0); } // start java telnet client // find arthas-client.jar URLClassLoader classLoader = new URLClassLoader( new URL[] { new File(arthasHomeDir, "arthas-client.jar").toURI().toURL() }); Class<?> telnetConsoleClas = classLoader.loadClass("com.taobao.arthas.client.TelnetConsole"); Method mainMethod = telnetConsoleClas.getMethod("main", String[].class); List<String> telnetArgs = new ArrayList<String>(); if (bootstrap.getCommand() != null) { telnetArgs.add("-c"); telnetArgs.add(bootstrap.getCommand()); } if (bootstrap.getBatchFile() != null) { telnetArgs.add("-f"); telnetArgs.add(bootstrap.getBatchFile()); } if (bootstrap.getHeight() != null) { telnetArgs.add("--height"); telnetArgs.add("" + bootstrap.getHeight()); } if (bootstrap.getWidth() != null) { telnetArgs.add("--width"); telnetArgs.add("" + bootstrap.getWidth()); } // telnet port ,ip telnetArgs.add(bootstrap.getTargetIpOrDefault()); telnetArgs.add("" + bootstrap.getTelnetPortOrDefault()); AnsiLog.info("arthas-client connect {} {}", bootstrap.getTargetIpOrDefault(), bootstrap.getTelnetPortOrDefault()); AnsiLog.debug("Start arthas-client.jar args: " + telnetArgs); // fix https://github.com/alibaba/arthas/issues/833 Thread.currentThread().setContextClassLoader(classLoader); mainMethod.invoke(null, new Object[] { telnetArgs.toArray(new String[0]) }); }
enforce use http to download arthas. default use https
main
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static void checkTelnetPortPid(Bootstrap bootstrap, long telnetPortPid, long targetPid) { if (telnetPortPid > 0 && targetPid != telnetPortPid) { AnsiLog.error("The telnet port {} is used by process {} instead of target process {}, you will connect to an unexpected process.", bootstrap.getTelnetPortOrDefault(), telnetPortPid, targetPid); AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it first with running the 'stop' command.", telnetPortPid); AnsiLog.error("2. Or try to stop the existing arthas instance: java -jar arthas-client.jar 127.0.0.1 {} -c \"stop\"", bootstrap.getTelnetPortOrDefault()); AnsiLog.error("3. Or try to use different telnet port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port -1"); System.exit(1); } }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
checkTelnetPortPid
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static long findProcessByTelnetClient(String arthasHomeDir, int telnetPort) { // start java telnet client List<String> telnetArgs = new ArrayList<String>(); telnetArgs.add("-c"); telnetArgs.add("session"); telnetArgs.add("--execution-timeout"); telnetArgs.add("2000"); // telnet port ,ip telnetArgs.add("127.0.0.1"); telnetArgs.add("" + telnetPort); try { ByteArrayOutputStream out = new ByteArrayOutputStream(1024); String error = null; int status = ProcessUtils.startArthasClient(arthasHomeDir, telnetArgs, out); if (status == STATUS_EXEC_TIMEOUT) { error = "detection timeout"; } else if (status == STATUS_EXEC_ERROR) { error = "detection error"; AnsiLog.error("process status: {}", status); AnsiLog.error("process output: {}", out.toString()); } else { // ignore connect error } if (error != null) { AnsiLog.error("The telnet port {} is used, but process {}, you will connect to an unexpected process.", telnetPort, error); AnsiLog.error("Try to use a different telnet port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port -1"); System.exit(1); } //parse output, find java pid String output = out.toString("UTF-8"); String javaPidLine = null; Scanner scanner = new Scanner(output); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.contains("JAVA_PID")) { javaPidLine = line; break; } } if (javaPidLine != null) { // JAVA_PID 10473 try { String[] strs = javaPidLine.split("JAVA_PID"); if (strs.length > 1) { return Long.parseLong(strs[strs.length - 1].trim()); } } catch (NumberFormatException e) { // ignore } } } catch (Throwable ex) { AnsiLog.error("Detection telnet port error"); AnsiLog.error(ex); } return -1; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
findProcessByTelnetClient
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static String listVersions() { StringBuilder result = new StringBuilder(1024); List<String> versionList = listNames(ARTHAS_LIB_DIR); Collections.sort(versionList); result.append("Local versions:\n"); for (String version : versionList) { result.append(" ").append(version).append('\n'); } result.append("Remote versions:\n"); List<String> remoteVersions = DownloadUtils.readRemoteVersions(); if (remoteVersions != null) { Collections.reverse(remoteVersions); for (String version : remoteVersions) { result.append(" " + version).append('\n'); } } else { result.append(" unknown\n"); } return result.toString(); }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
listVersions
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static List<String> listNames(File dir) { List<String> names = new ArrayList<String>(); if (!dir.exists()) { return names; } File[] files = dir.listFiles(); if (files == null) { return names; } for (File file : files) { String name = file.getName(); if (name.startsWith(".") || file.isFile()) { continue; } names.add(name); } return names; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
listNames
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static void verifyArthasHome(String arthasHome) { File home = new File(arthasHome); if (home.isDirectory()) { String[] fileList = { "arthas-core.jar", "arthas-agent.jar", "arthas-spy.jar" }; for (String fileName : fileList) { if (!new File(home, fileName).exists()) { throw new IllegalArgumentException( fileName + " do not exist, arthas home: " + home.getAbsolutePath()); } } return; } throw new IllegalArgumentException("illegal arthas home: " + home.getAbsolutePath()); }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
verifyArthasHome
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static String usage(CLI cli) { StringBuilder usageStringBuilder = new StringBuilder(); UsageMessageFormatter usageMessageFormatter = new UsageMessageFormatter(); usageMessageFormatter.setOptionComparator(null); cli.usage(usageStringBuilder, usageMessageFormatter); return UsageRender.render(usageStringBuilder.toString()); }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
usage
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getArthasHome() { return arthasHome; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getArthasHome
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getUseVersion() { return useVersion; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getUseVersion
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getRepoMirror() { return repoMirror; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getRepoMirror
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public boolean isUseHttp() { return useHttp; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
isUseHttp
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getTargetIp() { return targetIp; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getTargetIp
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getTargetIpOrDefault() { if (this.targetIp == null) { return DEFAULT_TARGET_IP; } else { return this.targetIp; } }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getTargetIpOrDefault
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public Integer getTelnetPort() { return telnetPort; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getTelnetPort
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public int getTelnetPortOrDefault() { if (this.telnetPort == null) { return DEFAULT_TELNET_PORT; } else { return this.telnetPort; } }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getTelnetPortOrDefault
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public Integer getHttpPort() { return httpPort; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getHttpPort
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public int getHttpPortOrDefault() { if (this.httpPort == null) { return DEFAULT_HTTP_PORT; } else { return this.httpPort; } }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getHttpPortOrDefault
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getCommand() { return command; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getCommand
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getBatchFile() { return batchFile; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getBatchFile
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public boolean isAttachOnly() { return attachOnly; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
isAttachOnly
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public long getPid() { return pid; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getPid
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public boolean isHelp() { return help; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
isHelp
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public Long getSessionTimeout() { return sessionTimeout; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getSessionTimeout
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public boolean isVerbose() { return verbose; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
isVerbose
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public boolean isVersions() { return versions; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
isVersions
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public Integer getHeight() { return height; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getHeight
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public Integer getWidth() { return width; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getWidth
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getTunnelServer() { return tunnelServer; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getTunnelServer
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getAgentId() { return agentId; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getAgentId
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getAppName() { return appName; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getAppName
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getStatUrl() { return statUrl; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getStatUrl
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getSelect() { return select; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getSelect
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getUsername() { return username; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getUsername
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getPassword() { return password; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getPassword
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
public String getDisabledCommands() { return disabledCommands; }
<pre> 1. get local latest version 2. get remote latest version 3. compare two version </pre>
getDisabledCommands
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java
Apache-2.0
private static URLConnection openURLConnection(String url) throws MalformedURLException, IOException { URLConnection connection = new URL(url).openConnection(); if (connection instanceof HttpURLConnection) { connection.setConnectTimeout(CONNECTION_TIMEOUT); // normally, 3xx is redirect int status = ((HttpURLConnection) connection).getResponseCode(); if (status != HttpURLConnection.HTTP_OK) { if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER) { String newUrl = connection.getHeaderField("Location"); AnsiLog.debug("Try to open url: {}, redirect to: {}", url, newUrl); return openURLConnection(newUrl); } } } return connection; }
support redirect @param url @return @throws MalformedURLException @throws IOException
openURLConnection
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java
Apache-2.0
private static String formatFileSize(long size) { String hrSize; double b = size; double k = size / 1024.0; double m = ((size / 1024.0) / 1024.0); double g = (((size / 1024.0) / 1024.0) / 1024.0); double t = ((((size / 1024.0) / 1024.0) / 1024.0) / 1024.0); DecimalFormat dec = new DecimalFormat("0.00"); if (t > 1) { hrSize = dec.format(t).concat(" TB"); } else if (g > 1) { hrSize = dec.format(g).concat(" GB"); } else if (m > 1) { hrSize = dec.format(m).concat(" MB"); } else if (k > 1) { hrSize = dec.format(k).concat(" KB"); } else { hrSize = dec.format(b).concat(" Bytes"); } return hrSize; }
support redirect @param url @return @throws MalformedURLException @throws IOException
formatFileSize
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java
Apache-2.0
public static String findJavaHome() { if (FOUND_JAVA_HOME != null) { return FOUND_JAVA_HOME; } String javaHome = System.getProperty("java.home"); if (JavaVersionUtils.isLessThanJava9()) { File toolsJar = new File(javaHome, "lib/tools.jar"); if (!toolsJar.exists()) { toolsJar = new File(javaHome, "../lib/tools.jar"); } if (!toolsJar.exists()) { // maybe jre toolsJar = new File(javaHome, "../../lib/tools.jar"); } if (toolsJar.exists()) { FOUND_JAVA_HOME = javaHome; return FOUND_JAVA_HOME; } if (!toolsJar.exists()) { AnsiLog.debug("Can not find tools.jar under java.home: " + javaHome); String javaHomeEnv = System.getenv("JAVA_HOME"); if (javaHomeEnv != null && !javaHomeEnv.isEmpty()) { AnsiLog.debug("Try to find tools.jar in System Env JAVA_HOME: " + javaHomeEnv); // $JAVA_HOME/lib/tools.jar toolsJar = new File(javaHomeEnv, "lib/tools.jar"); if (!toolsJar.exists()) { // maybe jre toolsJar = new File(javaHomeEnv, "../lib/tools.jar"); } } if (toolsJar.exists()) { AnsiLog.info("Found java home from System Env JAVA_HOME: " + javaHomeEnv); FOUND_JAVA_HOME = javaHomeEnv; return FOUND_JAVA_HOME; } throw new IllegalArgumentException("Can not find tools.jar under java home: " + javaHome + ", please try to start arthas-boot with full path java. Such as /opt/jdk/bin/java -jar arthas-boot.jar"); } } else { FOUND_JAVA_HOME = javaHome; } return FOUND_JAVA_HOME; }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
findJavaHome
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
public static void startArthasCore(long targetPid, List<String> attachArgs) { // find java/java.exe, then try to find tools.jar String javaHome = findJavaHome(); // find java/java.exe File javaPath = findJava(javaHome); if (javaPath == null) { throw new IllegalArgumentException( "Can not find java/java.exe executable file under java home: " + javaHome); } File toolsJar = findToolsJar(javaHome); if (JavaVersionUtils.isLessThanJava9()) { if (toolsJar == null || !toolsJar.exists()) { throw new IllegalArgumentException("Can not find tools.jar under java home: " + javaHome); } } List<String> command = new ArrayList<String>(); command.add(javaPath.getAbsolutePath()); if (toolsJar != null && toolsJar.exists()) { command.add("-Xbootclasspath/a:" + toolsJar.getAbsolutePath()); } command.addAll(attachArgs); // "${JAVA_HOME}"/bin/java \ // ${opts} \ // -jar "${arthas_lib_dir}/arthas-core.jar" \ // -pid ${TARGET_PID} \ // -target-ip ${TARGET_IP} \ // -telnet-port ${TELNET_PORT} \ // -http-port ${HTTP_PORT} \ // -core "${arthas_lib_dir}/arthas-core.jar" \ // -agent "${arthas_lib_dir}/arthas-agent.jar" ProcessBuilder pb = new ProcessBuilder(command); // https://github.com/alibaba/arthas/issues/2166 pb.environment().put("JAVA_TOOL_OPTIONS", ""); try { final Process proc = pb.start(); Thread redirectStdout = new Thread(new Runnable() { @Override public void run() { InputStream inputStream = proc.getInputStream(); try { IOUtils.copy(inputStream, System.out); } catch (IOException e) { IOUtils.close(inputStream); } } }); Thread redirectStderr = new Thread(new Runnable() { @Override public void run() { InputStream inputStream = proc.getErrorStream(); try { IOUtils.copy(inputStream, System.err); } catch (IOException e) { IOUtils.close(inputStream); } } }); redirectStdout.start(); redirectStderr.start(); redirectStdout.join(); redirectStderr.join(); int exitValue = proc.exitValue(); if (exitValue != 0) { AnsiLog.error("attach fail, targetPid: " + targetPid); System.exit(1); } } catch (Throwable e) { // ignore } }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
startArthasCore
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
@Override public void run() { InputStream inputStream = proc.getInputStream(); try { IOUtils.copy(inputStream, System.out); } catch (IOException e) { IOUtils.close(inputStream); } }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
run
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
@Override public void run() { InputStream inputStream = proc.getErrorStream(); try { IOUtils.copy(inputStream, System.err); } catch (IOException e) { IOUtils.close(inputStream); } }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
run
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
public static int startArthasClient(String arthasHomeDir, List<String> telnetArgs, OutputStream out) throws Throwable { // start java telnet client // find arthas-client.jar URLClassLoader classLoader = new URLClassLoader( new URL[]{new File(arthasHomeDir, "arthas-client.jar").toURI().toURL()}); Class<?> telnetConsoleClass = classLoader.loadClass("com.taobao.arthas.client.TelnetConsole"); Method processMethod = telnetConsoleClass.getMethod("process", String[].class); //redirect System.out/System.err PrintStream originSysOut = System.out; PrintStream originSysErr = System.err; PrintStream newOut = new PrintStream(out); PrintStream newErr = new PrintStream(out); // call TelnetConsole.process() // fix https://github.com/alibaba/arthas/issues/833 ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { System.setOut(newOut); System.setErr(newErr); Thread.currentThread().setContextClassLoader(classLoader); return (Integer) processMethod.invoke(null, new Object[]{telnetArgs.toArray(new String[0])}); } catch (Throwable e) { //java.lang.reflect.InvocationTargetException : java.net.ConnectException e = e.getCause(); if (e instanceof IOException || e instanceof InterruptedException) { // ignore connection error and interrupted error return STATUS_ERROR; } else { // process error AnsiLog.error("process error: {}", e.toString()); AnsiLog.error(e); return STATUS_EXEC_ERROR; } } finally { Thread.currentThread().setContextClassLoader(tccl); //reset System.out/System.err System.setOut(originSysOut); System.setErr(originSysErr); //flush output newOut.flush(); newErr.flush(); } }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
startArthasClient
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
private static File findJava(String javaHome) { String[] paths = { "bin/java", "bin/java.exe", "../bin/java", "../bin/java.exe" }; List<File> javaList = new ArrayList<File>(); for (String path : paths) { File javaFile = new File(javaHome, path); if (javaFile.exists()) { AnsiLog.debug("Found java: " + javaFile.getAbsolutePath()); javaList.add(javaFile); } } if (javaList.isEmpty()) { AnsiLog.debug("Can not find java/java.exe under current java home: " + javaHome); return null; } // find the shortest path, jre path longer than jdk path if (javaList.size() > 1) { Collections.sort(javaList, new Comparator<File>() { @Override public int compare(File file1, File file2) { try { return file1.getCanonicalPath().length() - file2.getCanonicalPath().length(); } catch (IOException e) { // ignore } return -1; } }); } return javaList.get(0); }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
findJava
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
@Override public int compare(File file1, File file2) { try { return file1.getCanonicalPath().length() - file2.getCanonicalPath().length(); } catch (IOException e) { // ignore } return -1; }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
compare
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
private static File findToolsJar(String javaHome) { if (JavaVersionUtils.isGreaterThanJava8()) { return null; } File toolsJar = new File(javaHome, "lib/tools.jar"); if (!toolsJar.exists()) { toolsJar = new File(javaHome, "../lib/tools.jar"); } if (!toolsJar.exists()) { // maybe jre toolsJar = new File(javaHome, "../../lib/tools.jar"); } if (!toolsJar.exists()) { throw new IllegalArgumentException("Can not find tools.jar under java home: " + javaHome); } AnsiLog.debug("Found tools.jar: " + toolsJar.getAbsolutePath()); return toolsJar; }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
findToolsJar
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
private static File findJps() { // Try to find jps under java.home and System env JAVA_HOME String javaHome = System.getProperty("java.home"); String[] paths = { "bin/jps", "bin/jps.exe", "../bin/jps", "../bin/jps.exe" }; List<File> jpsList = new ArrayList<File>(); for (String path : paths) { File jpsFile = new File(javaHome, path); if (jpsFile.exists()) { AnsiLog.debug("Found jps: " + jpsFile.getAbsolutePath()); jpsList.add(jpsFile); } } if (jpsList.isEmpty()) { AnsiLog.debug("Can not find jps under :" + javaHome); String javaHomeEnv = System.getenv("JAVA_HOME"); AnsiLog.debug("Try to find jps under env JAVA_HOME :" + javaHomeEnv); for (String path : paths) { File jpsFile = new File(javaHomeEnv, path); if (jpsFile.exists()) { AnsiLog.debug("Found jps: " + jpsFile.getAbsolutePath()); jpsList.add(jpsFile); } } } if (jpsList.isEmpty()) { AnsiLog.debug("Can not find jps under current java home: " + javaHome); return null; } // find the shortest path, jre path longer than jdk path if (jpsList.size() > 1) { Collections.sort(jpsList, new Comparator<File>() { @Override public int compare(File file1, File file2) { try { return file1.getCanonicalPath().length() - file2.getCanonicalPath().length(); } catch (IOException e) { // ignore } return -1; } }); } return jpsList.get(0); }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
findJps
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
@Override public int compare(File file1, File file2) { try { return file1.getCanonicalPath().length() - file2.getCanonicalPath().length(); } catch (IOException e) { // ignore } return -1; }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
compare
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
private static boolean isJpsProcess(String mainClassName) { return "sun.tools.jps.Jps".equals(mainClassName) || "jdk.jcmd/sun.tools.jps.Jps".equals(mainClassName); }
<pre> 1. Try to find java home from System Property java.home 2. If jdk > 8, FOUND_JAVA_HOME set to java.home 3. If jdk <= 8, try to find tools.jar under java.home 4. If tools.jar do not exists under java.home, try to find System env JAVA_HOME 5. If jdk <= 8 and tools.jar do not exists under JAVA_HOME, throw IllegalArgumentException </pre> @return
isJpsProcess
java
alibaba/arthas
boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
https://github.com/alibaba/arthas/blob/master/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java
Apache-2.0
public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput, final InputStream localInput, final Writer localOutput) { Thread reader, writer; reader = new Thread() { @Override public void run() { int ch; try { while (!interrupted() && (ch = localInput.read()) != -1) { remoteOutput.write(ch); remoteOutput.flush(); } } catch (IOException e) { // e.printStackTrace(); } } }; writer = new Thread() { @Override public void run() { try { InputStreamReader reader = new InputStreamReader(remoteInput); while (true) { int singleChar = reader.read(); if (singleChar == -1) { break; } localOutput.write(singleChar); localOutput.flush(); } } catch (IOException e) { e.printStackTrace(); } } }; writer.setPriority(Thread.currentThread().getPriority() + 1); writer.start(); reader.setDaemon(true); reader.start(); try { writer.join(); reader.interrupt(); } catch (InterruptedException e) { // Ignored } }
This is a utility class providing a reader/writer capability required by the weatherTelnet, rexec, rshell, and rlogin example programs. The only point of the class is to hold the static method readWrite which spawns a reader thread and a writer thread. The reader thread reads from a local input source (presumably stdin) and writes the data to a remote output destination. The writer thread reads from a remote input source and writes to a local output destination. The threads terminate when the remote input source closes. *
readWrite
java
alibaba/arthas
client/src/main/java/com/taobao/arthas/client/IOUtil.java
https://github.com/alibaba/arthas/blob/master/client/src/main/java/com/taobao/arthas/client/IOUtil.java
Apache-2.0