Skip to content

Commit

Permalink
pinpoint-apm#1298 fix unsafe resource cleanup of profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Dec 3, 2015
1 parent d5284f6 commit 3031068
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @author emeroad
*/
public class LoggingInterceptor implements StaticAroundInterceptor, AroundInterceptor {
public class LoggingInterceptor implements StaticAroundInterceptor, AroundInterceptor, AroundInterceptor0, AroundInterceptor1, AroundInterceptor2, AroundInterceptor3, AroundInterceptor4, AroundInterceptor5, ApiIdAwareAroundInterceptor {

private final Logger logger;

Expand Down Expand Up @@ -63,4 +63,72 @@ public static String defaultString(final Object object) {
return String.valueOf(object);
}

@Override
public void before(Object target, int apiId, Object[] args) {
}

@Override
public void after(Object target, int apiId, Object[] args, Object result, Throwable throwable) {

}

@Override
public void before(Object target) {

}

@Override
public void after(Object target, Object result, Throwable throwable) {

}

@Override
public void before(Object target, Object arg0) {

}

@Override
public void after(Object target, Object arg0, Object result, Throwable throwable) {

}

@Override
public void before(Object target, Object arg0, Object arg1) {

}

@Override
public void after(Object target, Object arg0, Object arg1, Object result, Throwable throwable) {

}

@Override
public void before(Object target, Object arg0, Object arg1, Object arg2) {

}

@Override
public void after(Object target, Object arg0, Object arg1, Object arg2, Object result, Throwable throwable) {

}

@Override
public void before(Object target, Object arg0, Object arg1, Object arg2, Object arg3) {

}

@Override
public void after(Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object result, Throwable throwable) {

}

@Override
public void before(Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4) {

}

@Override
public void after(Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4, Object result, Throwable throwable) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
public final class DefaultInterceptorRegistryAdaptor implements InterceptorRegistryAdaptor {
private static final LoggingInterceptor LOGGING_INTERCEPTOR = new LoggingInterceptor("com.navercorp.pinpoint.profiler.interceptor.LOGGING_INTERCEPTOR");

public static final InterceptorRegistry REGISTRY = new InterceptorRegistry();

private final static int DEFAULT_MAX = 4096;
private final int registrySize;

Expand Down Expand Up @@ -52,7 +50,11 @@ private int nextId() {
}

public Interceptor getInterceptor(int key) {
Interceptor interceptor = this.index.get(key);
return interceptor == null ? LOGGING_INTERCEPTOR : interceptor;
final Interceptor interceptor = this.index.get(key);
if (interceptor == null) {
return LOGGING_INTERCEPTOR;
} else {
return interceptor;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* *
* * Copyright 2014 NAVER Corp.
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package com.navercorp.pinpoint.bootstrap.interceptor.registry;

import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor;
import com.navercorp.pinpoint.bootstrap.interceptor.LoggingInterceptor;

/**
* @author emeroad
*/
public final class EmptyRegistryAdaptor implements InterceptorRegistryAdaptor {

public static final InterceptorRegistryAdaptor EMPTY = new EmptyRegistryAdaptor();

private static final LoggingInterceptor LOGGING_INTERCEPTOR = new LoggingInterceptor("com.navercorp.pinpoint.profiler.interceptor.EMPTY");

public EmptyRegistryAdaptor() {
}


@Override
public int addInterceptor(Interceptor interceptor) {
return -1;
}


public Interceptor getInterceptor(int key) {
return LOGGING_INTERCEPTOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class InterceptorRegistry {

private static final Locker LOCK = new DefaultLocker();

private static InterceptorRegistryAdaptor REGISTRY;
private static InterceptorRegistryAdaptor REGISTRY = EmptyRegistryAdaptor.EMPTY;

public static void bind(final InterceptorRegistryAdaptor interceptorRegistryAdaptor, final Object lock) {
if (interceptorRegistryAdaptor == null) {
Expand All @@ -42,7 +42,7 @@ public static void bind(final InterceptorRegistryAdaptor interceptorRegistryAdap

public static void unbind(final Object lock) {
if (LOCK.unlock(lock)) {
REGISTRY = null;
REGISTRY = EmptyRegistryAdaptor.EMPTY;
} else {
throw new IllegalStateException("unbind failed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ public void start() {

@Override
public void stop() {
stop(false);
}

public void stop(boolean staticResourceCleanup) {
synchronized (this) {
if (this.agentStatus == AgentStatus.RUNNING) {
changeStatus(AgentStatus.STOPPED);
Expand All @@ -408,9 +412,11 @@ public void stop() {
this.statDataSender.stop();

closeTcpDataSender();

PLoggerFactory.unregister(this.binder);
this.interceptorRegistryBinder.unbind();
// for testcase
if (staticResourceCleanup) {
PLoggerFactory.unregister(this.binder);
this.interceptorRegistryBinder.unbind();
}
}

private void closeTcpDataSender() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Class<?> getBaseTestClass() {
@Override
public void close() throws IOException {
if (mockAgent != null) {
mockAgent.stop();
mockAgent.stop(true);
}
PLoggerFactory.unregister(loggerBinder);
}
Expand Down

0 comments on commit 3031068

Please # to comment.