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 |
|---|---|---|---|---|---|---|---|
private boolean waitForJob(Job job, int timeout) {
long startTime = System.currentTimeMillis();
while (true) {
switch (job.status()) {
case STOPPED:
case TERMINATED:
return true;
}
if (System.currentTimeMillis() - startTime > timeout) {
return false;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
waitForJob
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
private synchronized Job createJob(List<CliToken> args, Session session, ResultDistributor resultDistributor) {
Job job = jobController.createJob(commandManager, args, session, new ApiJobHandler(session), new ApiTerm(session), resultDistributor);
return job;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
createJob
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
private Job createJob(String line, Session session, ResultDistributor resultDistributor) {
historyManager.addHistory(line);
return createJob(CliTokens.tokenize(line), session, resultDistributor);
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
createJob
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
private ApiResponse createResponse(ApiState apiState, String message) {
ApiResponse apiResponse = new ApiResponse();
apiResponse.setState(apiState);
apiResponse.setMessage(message);
return apiResponse;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
createResponse
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
private String getBody(FullHttpRequest request) {
ByteBuf buf = request.content();
return buf.toString(CharsetUtil.UTF_8);
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
getBody
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void onForeground(Job job) {
session.setForegroundJob(job);
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
onForeground
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void onBackground(Job job) {
if (session.getForegroundJob() == job) {
session.setForegroundJob(null);
updateSessionInputStatus(session, InputStatus.ALLOW_INPUT);
}
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
onBackground
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void onTerminated(Job job) {
if (session.getForegroundJob() == job) {
session.setForegroundJob(null);
updateSessionInputStatus(session, InputStatus.ALLOW_INPUT);
}
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
onTerminated
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void onSuspend(Job job) {
if (session.getForegroundJob() == job) {
session.setForegroundJob(null);
updateSessionInputStatus(session, InputStatus.ALLOW_INPUT);
}
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
onSuspend
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term resizehandler(Handler<Void> handler) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
resizehandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public String type() {
return "web";
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
type
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public int width() {
return 1000;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
width
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public int height() {
return 200;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
height
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term stdinHandler(Handler<String> handler) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
stdinHandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term stdoutHandler(Function<String, String> handler) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
stdoutHandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term write(String data) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
write
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public long lastAccessedTime() {
return session.getLastAccessTime();
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
lastAccessedTime
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term echo(String text) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
echo
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term setSession(Session session) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
setSession
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term interruptHandler(SignalHandler handler) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
interruptHandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term suspendHandler(SignalHandler handler) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
suspendHandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void readline(String prompt, Handler<String> lineHandler) {
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
readline
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void readline(String prompt, Handler<String> lineHandler, Handler<Completion> completionHandler) {
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
readline
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public Term closeHandler(Handler<Void> handler) {
return this;
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
closeHandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
public void close() {
}
|
Pull results from result queue
@param apiRequest
@param session
@return
|
close
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java
|
Apache-2.0
|
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > LRUCache.this.cacheSize;
}
|
Creates a new LRU cache.
@param cacheSize the maximum number of entries that will be kept in this
cache.
|
removeEldestEntry
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
Apache-2.0
|
public synchronized V get(K key) {
return map.get(key);
}
|
Retrieves an entry from the cache.<br>
The retrieved entry becomes the MRU (most recently used) entry.
@param key the key whose associated value is to be returned.
@return the value associated to this key, or null if no value with this key
exists in the cache.
|
get
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
Apache-2.0
|
public synchronized void put(K key, V value) {
map.put(key, value);
}
|
Adds an entry to this cache. The new entry becomes the MRU (most recently
used) entry. If an entry with the specified key already exists in the cache,
it is replaced by the new entry. If the cache is full, the LRU (least
recently used) entry is removed from the cache.
@param key the key with which the specified value is to be associated.
@param value a value to be associated with the specified key.
|
put
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
Apache-2.0
|
public synchronized int usedEntries() {
return map.size();
}
|
Returns the number of used entries in the cache.
@return the number of entries currently in the cache.
|
usedEntries
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
Apache-2.0
|
public synchronized Collection<Map.Entry<K, V>> getAll() {
return new ArrayList<Map.Entry<K, V>>(map.entrySet());
}
|
Returns a <code>Collection</code> that contains a copy of all cache entries.
@return a <code>Collection</code> with a copy of the cache content.
|
getAll
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java
|
Apache-2.0
|
@Override
public TermServer termHandler(Handler<Term> handler) {
this.termHandler = handler;
return this;
}
|
both suport http/telnet
@author hengyunabc 2019-11-04
|
termHandler
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
Apache-2.0
|
@Override
public TermServer listen(Handler<Future<TermServer>> listenHandler) {
// TODO: charset and inputrc from options
bootstrap = new NettyHttpTelnetTtyBootstrap(workerGroup, httpSessionManager).setHost(hostIp).setPort(port);
try {
bootstrap.start(new Consumer<TtyConnection>() {
@Override
public void accept(final TtyConnection conn) {
termHandler.handle(new TermImpl(Helper.loadKeymap(), conn));
}
}).get(connectionTimeout, TimeUnit.MILLISECONDS);
listenHandler.handle(Future.<TermServer>succeededFuture());
} catch (Throwable t) {
logger.error("Error listening to port " + port, t);
listenHandler.handle(Future.<TermServer>failedFuture(t));
}
return this;
}
|
both suport http/telnet
@author hengyunabc 2019-11-04
|
listen
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
Apache-2.0
|
@Override
public void accept(final TtyConnection conn) {
termHandler.handle(new TermImpl(Helper.loadKeymap(), conn));
}
|
both suport http/telnet
@author hengyunabc 2019-11-04
|
accept
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
Apache-2.0
|
@Override
public int actualPort() {
return bootstrap.getPort();
}
|
both suport http/telnet
@author hengyunabc 2019-11-04
|
actualPort
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
Apache-2.0
|
@Override
public void close() {
close(null);
}
|
both suport http/telnet
@author hengyunabc 2019-11-04
|
close
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
Apache-2.0
|
@Override
public void close(Handler<Future<Void>> completionHandler) {
if (bootstrap != null) {
bootstrap.stop();
if (completionHandler != null) {
completionHandler.handle(Future.<Void>succeededFuture());
}
} else {
if (completionHandler != null) {
completionHandler.handle(Future.<Void>failedFuture("telnet term server not started"));
}
}
}
|
both suport http/telnet
@author hengyunabc 2019-11-04
|
close
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java
|
Apache-2.0
|
public NettyHttpTelnetBootstrap setHost(String host) {
return (NettyHttpTelnetBootstrap) super.setHost(host);
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
setHost
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
public NettyHttpTelnetBootstrap setPort(int port) {
return (NettyHttpTelnetBootstrap) super.setPort(port);
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
setPort
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
@Override
public void start(Supplier<TelnetHandler> factory, Consumer<Throwable> doneHandler) {
// ignore, never invoke
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
start
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
public void start(final Supplier<TelnetHandler> handlerFactory, final Consumer<TtyConnection> factory,
final Consumer<Throwable> doneHandler) {
ServerBootstrap boostrap = new ServerBootstrap();
boostrap.group(group).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtocolDetectHandler(channelGroup, handlerFactory, factory, workerGroup, httpSessionManager));
}
});
boostrap.bind(getHost(), getPort()).addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (future.isSuccess()) {
doneHandler.accept(null);
} else {
doneHandler.accept(future.cause());
}
}
});
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
start
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtocolDetectHandler(channelGroup, handlerFactory, factory, workerGroup, httpSessionManager));
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
initChannel
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (future.isSuccess()) {
doneHandler.accept(null);
} else {
doneHandler.accept(future.cause());
}
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
operationComplete
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
@Override
public void stop(final Consumer<Throwable> doneHandler) {
GenericFutureListener<Future<Object>> adapter = new GenericFutureListener<Future<Object>>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
try {
doneHandler.accept(future.cause());
} finally {
group.shutdownGracefully();
}
}
};
channelGroup.close().addListener(adapter);
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
stop
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
@Override
public void operationComplete(Future<Object> future) throws Exception {
try {
doneHandler.accept(future.cause());
} finally {
group.shutdownGracefully();
}
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
operationComplete
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java
|
Apache-2.0
|
public String getHost() {
return httpTelnetTtyBootstrap.getHost();
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
getHost
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
Apache-2.0
|
public NettyHttpTelnetTtyBootstrap setHost(String host) {
httpTelnetTtyBootstrap.setHost(host);
return this;
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
setHost
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
Apache-2.0
|
public int getPort() {
return httpTelnetTtyBootstrap.getPort();
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
getPort
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
Apache-2.0
|
public NettyHttpTelnetTtyBootstrap setPort(int port) {
httpTelnetTtyBootstrap.setPort(port);
return this;
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
setPort
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
Apache-2.0
|
public boolean isOutBinary() {
return outBinary;
}
|
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@author hengyunabc 2019-11-05
|
isOutBinary
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
Apache-2.0
|
public NettyHttpTelnetTtyBootstrap setOutBinary(boolean outBinary) {
this.outBinary = outBinary;
return this;
}
|
Enable or disable the TELNET BINARY option on output.
@param outBinary
true to require the client to receive binary
@return this object
|
setOutBinary
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
Apache-2.0
|
public boolean isInBinary() {
return inBinary;
}
|
Enable or disable the TELNET BINARY option on output.
@param outBinary
true to require the client to receive binary
@return this object
|
isInBinary
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.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);
connection.setReadTimeout(READ_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");
logger.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
|
core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java
|
Apache-2.0
|
public static <E> boolean isIn(E e, E... s) {
if (null != s) {
for (E es : s) {
if (isEquals(e, es)) {
return true;
}
}
}
return false;
}
|
check whether a component is in an Array<br/>
@param e component
@param s array
@param <E> component type
@return <br/>
(1,1,2,3) == true
(1,2,3,4) == false
(null,1,null,2) == true
(1,null) == false
|
isIn
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/ArthasCheckUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ArthasCheckUtils.java
|
Apache-2.0
|
public static <E> boolean isEquals(E src, E target) {
return null == src
&& null == target
|| null != src
&& null != target
&& src.equals(target);
}
|
check whether two components are equal<br/>
@param src source component
@param target target component
@param <E> component type
@return <br/>
(null, null) == true
(1L,2L) == false
(1L,1L) == true
("abc",null) == false
(null,"abc") == false
|
isEquals
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/ArthasCheckUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ArthasCheckUtils.java
|
Apache-2.0
|
public static List<ClassLoader> getClassLoader(Instrumentation inst, String classLoaderClassName, String classLoaderToString) {
List<ClassLoader> matchClassLoaders = new ArrayList<ClassLoader>();
if (StringUtils.isEmpty(classLoaderClassName) && StringUtils.isEmpty(classLoaderToString)) {
return matchClassLoaders;
}
Set<ClassLoader> classLoaderSet = getAllClassLoader(inst);
List<ClassLoader> matchedByClassLoaderToStr = new ArrayList<ClassLoader>();
for (ClassLoader classLoader : classLoaderSet) {
// only classLoaderClassName
if (!StringUtils.isEmpty(classLoaderClassName) && StringUtils.isEmpty(classLoaderToString)) {
if (classLoader.getClass().getName().equals(classLoaderClassName)) {
matchClassLoaders.add(classLoader);
}
}
// only classLoaderToString
else if (!StringUtils.isEmpty(classLoaderToString) && StringUtils.isEmpty(classLoaderClassName)) {
if (classLoader.toString().equals(classLoaderToString)) {
matchClassLoaders.add(classLoader);
}
}
// classLoaderClassName and classLoaderToString
else {
if (classLoader.getClass().getName().equals(classLoaderClassName)) {
matchClassLoaders.add(classLoader);
}
if (classLoader.toString().equals(classLoaderToString)) {
matchedByClassLoaderToStr.add(classLoader);
}
}
}
// classLoaderClassName and classLoaderToString
if (!StringUtils.isEmpty(classLoaderClassName) && !StringUtils.isEmpty(classLoaderToString)) {
matchClassLoaders.retainAll(matchedByClassLoaderToStr);
}
return matchClassLoaders;
}
|
Find List<ClassLoader> by the class name of ClassLoader or the return value of ClassLoader#toString().
@param inst
@param classLoaderClassName
@param classLoaderToString
@return
|
getClassLoader
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/ClassLoaderUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ClassLoaderUtils.java
|
Apache-2.0
|
@SuppressWarnings({ "unchecked", "restriction" })
public static URL[] getUrls(ClassLoader classLoader) {
if (classLoader instanceof URLClassLoader) {
try {
return ((URLClassLoader) classLoader).getURLs();
} catch (Throwable e) {
logger.error("classLoader: {} getUrls error", classLoader, e);
}
}
// jdk9
if (classLoader.getClass().getName().startsWith("jdk.internal.loader.ClassLoaders$")) {
try {
Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
sun.misc.Unsafe unsafe = (sun.misc.Unsafe) field.get(null);
Class<?> ucpOwner = classLoader.getClass();
Field ucpField = null;
// jdk 9~15: jdk.internal.loader.ClassLoaders$AppClassLoader.ucp
// jdk 16~17: jdk.internal.loader.BuiltinClassLoader.ucp
while (ucpField == null && !ucpOwner.getName().equals("java.lang.Object")) {
try {
ucpField = ucpOwner.getDeclaredField("ucp");
} catch (NoSuchFieldException ex) {
ucpOwner = ucpOwner.getSuperclass();
}
}
if (ucpField == null) {
return null;
}
long ucpFieldOffset = unsafe.objectFieldOffset(ucpField);
Object ucpObject = unsafe.getObject(classLoader, ucpFieldOffset);
if (ucpObject == null) {
return null;
}
// jdk.internal.loader.URLClassPath.path
Field pathField = ucpField.getType().getDeclaredField("path");
if (pathField == null) {
return null;
}
long pathFieldOffset = unsafe.objectFieldOffset(pathField);
ArrayList<URL> path = (ArrayList<URL>) unsafe.getObject(ucpObject, pathFieldOffset);
return path.toArray(new URL[path.size()]);
} catch (Throwable e) {
// ignore
return null;
}
}
return null;
}
|
Find List<ClassLoader> by the class name of ClassLoader or the return value of ClassLoader#toString().
@param inst
@param classLoaderClassName
@param classLoaderToString
@return
|
getUrls
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/ClassLoaderUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ClassLoaderUtils.java
|
Apache-2.0
|
public static void end(CommandProcess process, ExitStatus status) {
if (status != null) {
process.end(status.getStatusCode(), status.getMessage());
} else {
process.end(-1, "process error, exit status is null");
}
}
|
check exit status and end command processing
@param process CommandProcess instance
@param status ExitStatus of command
|
end
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/CommandUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/CommandUtils.java
|
Apache-2.0
|
public static String decompile(String classFilePath, String methodName, boolean hideUnicode,
boolean printLineNumber) {
return decompileWithMappings(classFilePath, methodName, hideUnicode, printLineNumber).getFirst();
}
|
@see org.benf.cfr.reader.util.MiscConstants.Version.getVersion() Currently,
the cfr version is wrong. so disable show cfr version.
|
decompile
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/Decompiler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/Decompiler.java
|
Apache-2.0
|
private static String addLineNumber(String src, Map<Integer, Integer> lineMapping) {
int maxLineNumber = 0;
for (Integer value : lineMapping.values()) {
if (value != null && value > maxLineNumber) {
maxLineNumber = value;
}
}
String formatStr = "/*%2d*/ ";
String emptyStr = " ";
StringBuilder sb = new StringBuilder();
List<String> lines = StringUtils.toLines(src);
if (maxLineNumber >= 1000) {
formatStr = "/*%4d*/ ";
emptyStr = " ";
} else if (maxLineNumber >= 100) {
formatStr = "/*%3d*/ ";
emptyStr = " ";
}
int index = 0;
for (String line : lines) {
Integer srcLineNumber = lineMapping.get(index + 1);
if (srcLineNumber != null) {
sb.append(String.format(formatStr, srcLineNumber));
} else {
sb.append(emptyStr);
}
sb.append(line).append("\n");
index++;
}
return sb.toString();
}
|
@see org.benf.cfr.reader.util.MiscConstants.Version.getVersion() Currently,
the cfr version is wrong. so disable show cfr version.
|
addLineNumber
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/Decompiler.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/Decompiler.java
|
Apache-2.0
|
public static void writeByteArrayToFile(File file, byte[] data) throws IOException {
writeByteArrayToFile(file, data, false);
}
|
Writes a byte array to a file creating the file if it does not exist.
<p>
NOTE: As from v1.3, the parent directories of the file will be created
if they do not exist.
@param file the file to write to
@param data the content to write to the file
@throws IOException in case of an I/O error
@since 1.1
|
writeByteArrayToFile
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException {
try (OutputStream out = openOutputStream(file, append)) {
out.write(data);
}
// ignore
}
|
Writes a byte array to a file creating the file if it does not exist.
@param file the file to write to
@param data the content to write to the file
@param append if {@code true}, then bytes will be added to the
end of the file rather than overwriting
@throws IOException in case of an I/O error
@since IO 2.1
|
writeByteArrayToFile
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static FileOutputStream openOutputStream(File file, boolean append) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
}
if (!file.canWrite()) {
throw new IOException("File '" + file + "' cannot be written to");
}
} else {
File parent = file.getParentFile();
if (parent != null) {
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new IOException("Directory '" + parent + "' could not be created");
}
}
}
return new FileOutputStream(file, append);
}
|
Opens a {@link FileOutputStream} for the specified file, checking and
creating the parent directory if it does not exist.
<p>
At the end of the method either the stream will be successfully opened,
or an exception will have been thrown.
<p>
The parent directory will be created if it does not exist.
The file will be created if it does not exist.
An exception is thrown if the file object exists but is a directory.
An exception is thrown if the file exists but cannot be written to.
An exception is thrown if the parent directory cannot be created.
@param file the file to open for output, must not be {@code null}
@param append if {@code true}, then bytes will be added to the
end of the file rather than overwriting
@return a new {@link FileOutputStream} for the specified file
@throws IOException if the file object is a directory
@throws IOException if the file cannot be written to
@throws IOException if a parent directory needs creating but that fails
@since 2.1
|
openOutputStream
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static void saveCommandHistory(List<int[]> history, File file) {
try (OutputStream out = new BufferedOutputStream(openOutputStream(file, false))) {
for (int[] command : history) {
String commandStr = Helper.fromCodePoints(command);
if (isAuthCommand(commandStr)) {
command = AUTH_CODEPOINTS;
}
for (int i : command) {
out.write(i);
}
out.write('\n');
}
} catch (IOException e) {
// ignore
}
// ignore
}
|
save the command history to the given file, data will be overridden.
@param history the command history, each represented by an int array
@param file the file to save the history
|
saveCommandHistory
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static List<int[]> loadCommandHistory(File file) {
BufferedReader br = null;
List<int[]> history = new ArrayList<>();
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line;
while ((line = br.readLine()) != null) {
history.add(Helper.toCodePoints(line));
}
} catch (IOException e) {
// ignore
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ioe) {
// ignore
}
}
return history;
}
|
save the command history to the given file, data will be overridden.
@param history the command history, each represented by an int array
@param file the file to save the history
|
loadCommandHistory
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static void saveCommandHistoryString(List<String> history, File file) {
try (OutputStream out = new BufferedOutputStream(openOutputStream(file, false))) {
for (String command : history) {
if (!StringUtils.isBlank(command)) {
if (isAuthCommand(command)) {
command = ArthasConstants.AUTH;
}
out.write(command.getBytes("utf-8"));
out.write('\n');
}
}
} catch (IOException e) {
// ignore
}
// ignore
}
|
save the command history to the given file, data will be overridden.
@param history the command history
@param file the file to save the history
|
saveCommandHistoryString
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static List<String> loadCommandHistoryString(File file) {
BufferedReader br = null;
List<String> history = new ArrayList<>();
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
String line;
while ((line = br.readLine()) != null) {
if (!StringUtils.isBlank(line)) {
history.add(line);
}
}
} catch (IOException e) {
// ignore
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ioe) {
// ignore
}
}
return history;
}
|
save the command history to the given file, data will be overridden.
@param history the command history
@param file the file to save the history
|
loadCommandHistoryString
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static String readFileToString(File file, Charset encoding) throws IOException {
try (FileInputStream stream = new FileInputStream(file)) {
Reader reader = new BufferedReader(new InputStreamReader(stream, encoding));
StringBuilder builder = new StringBuilder();
char[] buffer = new char[8192];
int read;
while ((read = reader.read(buffer, 0, buffer.length)) > 0) {
builder.append(buffer, 0, read);
}
return builder.toString();
}
}
|
save the command history to the given file, data will be overridden.
@param history the command history
@param file the file to save the history
|
readFileToString
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static Properties readProperties(String file) throws IOException {
Properties properties = new Properties();
FileInputStream in = null;
try {
in = new FileInputStream(file);
properties.load(in);
return properties;
} finally {
com.taobao.arthas.common.IOUtils.close(in);
}
}
|
save the command history to the given file, data will be overridden.
@param history the command history
@param file the file to save the history
|
readProperties
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static boolean isDirectoryOrNotExist(String path) {
File file = new File(path);
return !file.exists() || file.isDirectory();
}
|
Check if the given path is a directory or not exists.
@param path path of file.
@return {@code true} if the path is not exist or is an existing directory, otherwise returns {@code false}.
|
isDirectoryOrNotExist
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java
|
Apache-2.0
|
public static String getCookieValue(Set<Cookie> cookies, String cookieName) {
for (Cookie cookie : cookies) {
if(cookie.name().equals(cookieName)){
return cookie.value();
}
}
return null;
}
|
Get cookie value by name
@param cookies request cookies
@param cookieName the cookie name
|
getCookieValue
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
Apache-2.0
|
public static void setCookie(DefaultFullHttpResponse response, String name, String value) {
response.headers().add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(name, value));
}
|
@param response
@param name
@param value
|
setCookie
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
Apache-2.0
|
public static DefaultHttpResponse createResponse(FullHttpRequest request, HttpResponseStatus status, String content) {
DefaultFullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(), status);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=utf-8");
try {
response.content().writeBytes(content.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
}
return response;
}
|
Create http response with status code and content
@param request request
@param status response status code
@param content response content
|
createResponse
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
Apache-2.0
|
public static HttpResponse createRedirectResponse(FullHttpRequest request, String url) {
DefaultFullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.FOUND);
response.headers().set(HttpHeaderNames.LOCATION, url);
return response;
}
|
Create http response with status code and content
@param request request
@param status response status code
@param content response content
|
createRedirectResponse
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/HttpUtils.java
|
Apache-2.0
|
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output);
return output.toByteArray();
}
|
Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
<p>
This method buffers the input internally, so there is no need to use a
<code>BufferedInputStream</code>.
@param input the <code>InputStream</code> to read from
@return the requested byte array
@throws NullPointerException if the input is null
@throws IOException if an I/O error occurs
|
toByteArray
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
Apache-2.0
|
public static int copy(InputStream input, OutputStream output) throws IOException {
long count = copyLarge(input, output);
if (count > Integer.MAX_VALUE) {
return -1;
}
return (int) count;
}
|
Copy bytes from an <code>InputStream</code> to an
<code>OutputStream</code>.
<p>
This method buffers the input internally, so there is no need to use a
<code>BufferedInputStream</code>.
<p>
Large streams (over 2GB) will return a bytes copied value of
<code>-1</code> after the copy has completed since the correct
number of bytes cannot be returned as an int. For large streams
use the <code>copyLarge(InputStream, OutputStream)</code> method.
@param input the <code>InputStream</code> to read from
@param output the <code>OutputStream</code> to write to
@return the number of bytes copied, or -1 if > Integer.MAX_VALUE
@throws NullPointerException if the input or output is null
@throws IOException if an I/O error occurs
@since 1.1
|
copy
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
Apache-2.0
|
public static long copyLarge(InputStream input, OutputStream output)
throws IOException {
return copyLarge(input, output, new byte[DEFAULT_BUFFER_SIZE]);
}
|
Copy bytes from a large (over 2GB) <code>InputStream</code> to an
<code>OutputStream</code>.
<p>
This method buffers the input internally, so there is no need to use a
<code>BufferedInputStream</code>.
<p>
The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
@param input the <code>InputStream</code> to read from
@param output the <code>OutputStream</code> to write to
@return the number of bytes copied
@throws NullPointerException if the input or output is null
@throws IOException if an I/O error occurs
@since 1.3
|
copyLarge
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
Apache-2.0
|
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer)
throws IOException {
long count = 0;
int n = 0;
while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
|
Copy bytes from a large (over 2GB) <code>InputStream</code> to an
<code>OutputStream</code>.
<p>
This method uses the provided buffer, so there is no need to use a
<code>BufferedInputStream</code>.
<p>
@param input the <code>InputStream</code> to read from
@param output the <code>OutputStream</code> to write to
@param buffer the buffer to use for the copy
@return the number of bytes copied
@throws NullPointerException if the input or output is null
@throws IOException if an I/O error occurs
@since 2.2
|
copyLarge
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
Apache-2.0
|
public static String toString(InputStream input) throws IOException {
BufferedReader br = null;
try {
StringBuilder sb = new StringBuilder();
br = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
return sb.toString();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
// ignore
}
}
}
}
|
Get the contents of an <code>InputStream</code> as a String
using the default character encoding of the platform.
<p>
This method buffers the input internally, so there is no need to use a
<code>BufferedInputStream</code>.
@param input the <code>InputStream</code> to read from
@return the requested String
@throws NullPointerException if the input is null
@throws IOException if an I/O error occurs
|
toString
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/IOUtils.java
|
Apache-2.0
|
public static boolean isWindowsOS() {
String osName = System.getProperty(OS_NAME);
return osName.toLowerCase().contains(WINDOWS);
}
|
check: whether current operating system is windows
@return true---is windows
|
isWindowsOS
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/IPUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/IPUtils.java
|
Apache-2.0
|
public static String simpleRequest(String url) {
BufferedReader br = null;
try {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty("Accept", "application/json");
int responseCode = con.getResponseCode();
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
String result = sb.toString().trim();
if (responseCode == 500) {
JSONObject errorObj = JSON.parseObject(result);
if (errorObj.containsKey("errorMsg")) {
return errorObj.getString("errorMsg");
}
return result;
} else {
return result;
}
} catch (Exception e) {
return null;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
// ignore
}
}
}
}
|
@deprecated
This implementation is based on HttpURLConnection,
which can not detail with status code other than 200.
@param url the requested url
@return the response string of given url
|
simpleRequest
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
Apache-2.0
|
public static Response requestViaSocket(String path) {
BufferedReader br = null;
try {
Socket s = new Socket(QOS_HOST, QOS_PORT);
PrintWriter pw = new PrintWriter(s.getOutputStream());
pw.println("GET " + path + " HTTP/1.1");
pw.println("Host: " + QOS_HOST + ":" + QOS_PORT);
pw.println("");
pw.flush();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
boolean start = false;
while ((line = br.readLine()) != null) {
if (start) {
sb.append(line).append("\n");
}
if (line.equals(QOS_RESPONSE_START_LINE)) {
start = true;
}
}
String result = sb.toString().trim();
return new Response(result);
} catch (Exception e) {
return new Response(e.getMessage(), false);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
// ignore
}
}
}
}
|
Only use this method when tomcat monitor version <= 1.0.1
This will send http request to pandora qos port 12201,
and display the response.
Note that pandora qos response is not fully HTTP compatible under version 2.1.0,
so we filtered some of the content and only display useful content.
@param path the path relative to http://localhost:12201
e.g. /pandora/ls
For commands that requires arguments, use the following format
e.g. /pandora/find?arg0=RPCProtocolService
Note that the parameter name is never used in pandora qos,
so the name(e.g. arg0) is irrelevant.
@return the qos response in string format
|
requestViaSocket
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
Apache-2.0
|
public boolean isSuccess() {
return success;
}
|
Only use this method when tomcat monitor version <= 1.0.1
This will send http request to pandora qos port 12201,
and display the response.
Note that pandora qos response is not fully HTTP compatible under version 2.1.0,
so we filtered some of the content and only display useful content.
@param path the path relative to http://localhost:12201
e.g. /pandora/ls
For commands that requires arguments, use the following format
e.g. /pandora/find?arg0=RPCProtocolService
Note that the parameter name is never used in pandora qos,
so the name(e.g. arg0) is irrelevant.
@return the qos response in string format
|
isSuccess
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
Apache-2.0
|
public String getContent() {
return content;
}
|
Only use this method when tomcat monitor version <= 1.0.1
This will send http request to pandora qos port 12201,
and display the response.
Note that pandora qos response is not fully HTTP compatible under version 2.1.0,
so we filtered some of the content and only display useful content.
@param path the path relative to http://localhost:12201
e.g. /pandora/ls
For commands that requires arguments, use the following format
e.g. /pandora/find?arg0=RPCProtocolService
Note that the parameter name is never used in pandora qos,
so the name(e.g. arg0) is irrelevant.
@return the qos response in string format
|
getContent
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
Apache-2.0
|
public static boolean serverListening(String host, int port) {
Socket s = null;
try {
s = new Socket(host, port);
return true;
} catch (Exception e) {
return false;
} finally {
if (s != null) {
try {
s.close();
} catch (Exception e) {
// ignore
}
}
}
}
|
Test if a port is open on the give host
|
serverListening
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
|
Apache-2.0
|
public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
|
<p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
<pre>
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
</pre>
@param cs the CharSequence to check, may be null
@return {@code true} if the CharSequence is null, empty or whitespace
@since 2.0
@since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
|
isBlank
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String repeat(final String str, final int repeat) {
// Performance tuned for 2.0 (JDK1.4)
if (str == null) {
return null;
}
if (repeat <= 0) {
return Constants.EMPTY_STRING;
}
final int inputLength = str.length();
if (repeat == 1 || inputLength == 0) {
return str;
}
if (inputLength == 1 && repeat <= PAD_LIMIT) {
return repeat(str.charAt(0), repeat);
}
final int outputLength = inputLength * repeat;
switch (inputLength) {
case 1 :
return repeat(str.charAt(0), repeat);
case 2 :
final char ch0 = str.charAt(0);
final char ch1 = str.charAt(1);
final char[] output2 = new char[outputLength];
for (int i = repeat * 2 - 2; i >= 0; i--, i--) {
output2[i] = ch0;
output2[i + 1] = ch1;
}
return new String(output2);
default :
final StringBuilder buf = new StringBuilder(outputLength);
for (int i = 0; i < repeat; i++) {
buf.append(str);
}
return buf.toString();
}
}
|
<p>Repeat a String {@code repeat} times to form a
new String.</p>
<pre>
StringUtils.repeat(null, 2) = null
StringUtils.repeat("", 0) = ""
StringUtils.repeat("", 2) = ""
StringUtils.repeat("a", 3) = "aaa"
StringUtils.repeat("ab", 2) = "abab"
StringUtils.repeat("a", -2) = ""
</pre>
@param str the String to repeat, may be null
@param repeat number of times to repeat str, negative treated as zero
@return a new String consisting of the original String repeated,
{@code null} if null String input
|
repeat
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static int length(final CharSequence cs) {
return cs == null ? 0 : cs.length();
}
|
Gets a CharSequence length or {@code 0} if the CharSequence is
{@code null}.
@param cs
a CharSequence or {@code null}
@return CharSequence length or {@code 0} if the CharSequence is
{@code null}.
@since 2.4
@since 3.0 Changed signature from length(String) to length(CharSequence)
|
length
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String stripEnd(final String str, final String stripChars) {
int end;
if (str == null || (end = str.length()) == 0) {
return str;
}
if (stripChars == null) {
while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) {
end--;
}
} else if (stripChars.isEmpty()) {
return str;
} else {
while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND) {
end--;
}
}
return str.substring(0, end);
}
|
<p>Strips any of a set of characters from the end of a String.</p>
<p>A {@code null} input String returns {@code null}.
An empty string ("") input returns the empty string.</p>
<p>If the stripChars String is {@code null}, whitespace is
stripped as defined by {@link Character#isWhitespace(char)}.</p>
<pre>
StringUtils.stripEnd(null, *) = null
StringUtils.stripEnd("", *) = ""
StringUtils.stripEnd("abc", "") = "abc"
StringUtils.stripEnd("abc", null) = "abc"
StringUtils.stripEnd(" abc", null) = " abc"
StringUtils.stripEnd("abc ", null) = "abc"
StringUtils.stripEnd(" abc ", null) = " abc"
StringUtils.stripEnd(" abcyx", "xyz") = " abc"
StringUtils.stripEnd("120.00", ".0") = "12"
</pre>
@param str the String to remove characters from, may be null
@param stripChars the set of characters to remove, null treated as whitespace
@return the stripped String, {@code null} if null String input
|
stripEnd
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String classLoaderHash(Class<?> clazz) {
if (clazz == null || clazz.getClassLoader() == null) {
return "null";
}
return Integer.toHexString(clazz.getClassLoader().hashCode());
}
|
<p>Strips any of a set of characters from the end of a String.</p>
<p>A {@code null} input String returns {@code null}.
An empty string ("") input returns the empty string.</p>
<p>If the stripChars String is {@code null}, whitespace is
stripped as defined by {@link Character#isWhitespace(char)}.</p>
<pre>
StringUtils.stripEnd(null, *) = null
StringUtils.stripEnd("", *) = ""
StringUtils.stripEnd("abc", "") = "abc"
StringUtils.stripEnd("abc", null) = "abc"
StringUtils.stripEnd(" abc", null) = " abc"
StringUtils.stripEnd("abc ", null) = "abc"
StringUtils.stripEnd(" abc ", null) = " abc"
StringUtils.stripEnd(" abcyx", "xyz") = " abc"
StringUtils.stripEnd("120.00", ".0") = "12"
</pre>
@param str the String to remove characters from, may be null
@param stripChars the set of characters to remove, null treated as whitespace
@return the stripped String, {@code null} if null String input
|
classLoaderHash
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String humanReadableByteCount(long bytes) {
return bytes < 1024L ? bytes + " B"
: bytes < 0xfffccccccccccccL >> 40 ? String.format("%.1f KiB", bytes / 0x1p10)
: bytes < 0xfffccccccccccccL >> 30 ? String.format("%.1f MiB", bytes / 0x1p20)
: bytes < 0xfffccccccccccccL >> 20 ? String.format("%.1f GiB", bytes / 0x1p30)
: bytes < 0xfffccccccccccccL >> 10 ? String.format("%.1f TiB", bytes / 0x1p40)
: bytes < 0xfffccccccccccccL ? String.format("%.1f PiB", (bytes >> 10) / 0x1p40)
: String.format("%.1f EiB", (bytes >> 20) / 0x1p40);
}
|
format byte size to human readable format. https://stackoverflow.com/a/3758880
@param bytes byets
@return human readable format
|
humanReadableByteCount
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static List<String> toLines(String text) {
List<String> result = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new StringReader(text));
try {
String line = reader.readLine();
while (line != null) {
result.add(line);
line = reader.readLine();
}
} catch (IOException exc) {
// quit
} finally {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
return result;
}
|
format byte size to human readable format. https://stackoverflow.com/a/3758880
@param bytes byets
@return human readable format
|
toLines
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String randomString(int length) {
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++)
sb.append(AB.charAt(ThreadLocalRandom.current().nextInt(AB.length())));
return sb.toString();
}
|
format byte size to human readable format. https://stackoverflow.com/a/3758880
@param bytes byets
@return human readable format
|
randomString
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String before(String text, String before) {
int pos = text.indexOf(before);
return pos == -1 ? null : text.substring(0, pos);
}
|
Returns the string before the given token
@param text the text
@param before the token
@return the text before the token, or <tt>null</tt> if text does not contain
the token
|
before
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String after(String text, String after) {
int pos = text.indexOf(after);
if (pos == -1) {
return null;
}
return text.substring(pos + after.length());
}
|
Returns the string after the given token
@param text the text
@param after the token
@return the text after the token, or <tt>null</tt> if text does not contain
the token
|
after
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String[] splitMethodInfo(String methodInfo) {
int index = methodInfo.indexOf('|');
return new String[] { methodInfo.substring(0, index), methodInfo.substring(index + 1) };
}
|
Returns the string after the given token
@param text the text
@param after the token
@return the text after the token, or <tt>null</tt> if text does not contain
the token
|
splitMethodInfo
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String[] splitInvokeInfo(String invokeInfo) {
int index1 = invokeInfo.indexOf('|');
int index2 = invokeInfo.indexOf('|', index1 + 1);
int index3 = invokeInfo.indexOf('|', index2 + 1);
return new String[] { invokeInfo.substring(0, index1), invokeInfo.substring(index1 + 1, index2),
invokeInfo.substring(index2 + 1, index3), invokeInfo.substring(index3 + 1) };
}
|
Returns the string after the given token
@param text the text
@param after the token
@return the text after the token, or <tt>null</tt> if text does not contain
the token
|
splitInvokeInfo
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static String beautifyName(String name) {
return name.replace(' ', '_').toLowerCase();
}
|
Returns the string after the given token
@param text the text
@param after the token
@return the text after the token, or <tt>null</tt> if text does not contain
the token
|
beautifyName
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static List<String> toStringList(URL[] urls) {
if (urls != null) {
List<String> result = new ArrayList<String>(urls.length);
for (URL url : urls) {
result.add(url.toString());
}
return result;
}
return Collections.emptyList();
}
|
Returns the string after the given token
@param text the text
@param after the token
@return the text after the token, or <tt>null</tt> if text does not contain
the token
|
toStringList
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java
|
Apache-2.0
|
public static BlockingLockInfo findMostBlockingLock() {
ThreadInfo[] infos = threadMXBean.dumpAllThreads(threadMXBean.isObjectMonitorUsageSupported(),
threadMXBean.isSynchronizerUsageSupported());
// a map of <LockInfo.getIdentityHashCode, number of thread blocking on this>
Map<Integer, Integer> blockCountPerLock = new HashMap<Integer, Integer>();
// a map of <LockInfo.getIdentityHashCode, the thread info that holding this lock
Map<Integer, ThreadInfo> ownerThreadPerLock = new HashMap<Integer, ThreadInfo>();
for (ThreadInfo info: infos) {
if (info == null) {
continue;
}
LockInfo lockInfo = info.getLockInfo();
if (lockInfo != null) {
// the current thread is blocked waiting on some condition
if (blockCountPerLock.get(lockInfo.getIdentityHashCode()) == null) {
blockCountPerLock.put(lockInfo.getIdentityHashCode(), 0);
}
int blockedCount = blockCountPerLock.get(lockInfo.getIdentityHashCode());
blockCountPerLock.put(lockInfo.getIdentityHashCode(), blockedCount + 1);
}
for (MonitorInfo monitorInfo: info.getLockedMonitors()) {
// the object monitor currently held by this thread
if (ownerThreadPerLock.get(monitorInfo.getIdentityHashCode()) == null) {
ownerThreadPerLock.put(monitorInfo.getIdentityHashCode(), info);
}
}
for (LockInfo lockedSync: info.getLockedSynchronizers()) {
// the ownable synchronizer currently held by this thread
if (ownerThreadPerLock.get(lockedSync.getIdentityHashCode()) == null) {
ownerThreadPerLock.put(lockedSync.getIdentityHashCode(), info);
}
}
}
// find the thread that is holding the lock that blocking the largest number of threads.
int mostBlockingLock = 0; // System.identityHashCode(null) == 0
int maxBlockingCount = 0;
for (Map.Entry<Integer, Integer> entry: blockCountPerLock.entrySet()) {
if (entry.getValue() > maxBlockingCount && ownerThreadPerLock.get(entry.getKey()) != null) {
// the lock is explicitly held by anther thread.
maxBlockingCount = entry.getValue();
mostBlockingLock = entry.getKey();
}
}
if (mostBlockingLock == 0) {
// nothing found
return EMPTY_INFO;
}
BlockingLockInfo blockingLockInfo = new BlockingLockInfo();
blockingLockInfo.setThreadInfo(ownerThreadPerLock.get(mostBlockingLock));
blockingLockInfo.setLockIdentityHashCode(mostBlockingLock);
blockingLockInfo.setBlockingThreadCount(blockCountPerLock.get(mostBlockingLock));
return blockingLockInfo;
}
|
Find the thread and lock that is blocking the most other threads.
Time complexity of this algorithm: O(number of thread)
Space complexity of this algorithm: O(number of locks)
@return the BlockingLockInfo object, or an empty object if not found.
|
findMostBlockingLock
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java
|
Apache-2.0
|
public static String getFullStacktrace(ThreadInfo threadInfo) {
return getFullStacktrace(threadInfo, -1, -1, -1, 0, 0);
}
|
Find the thread and lock that is blocking the most other threads.
Time complexity of this algorithm: O(number of thread)
Space complexity of this algorithm: O(number of locks)
@return the BlockingLockInfo object, or an empty object if not found.
|
getFullStacktrace
|
java
|
alibaba/arthas
|
core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java
|
https://github.com/alibaba/arthas/blob/master/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.