All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.linyimin0812.Bridge Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
/*
 * Copyright The Arthas Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.github.linyimin0812;

/**
 * @author linyimin
 **/
public class Bridge {

    public static final AbstractBridge NOP_BRIDGE = new NopBridge();

    private static AbstractBridge bridgeInstance = NOP_BRIDGE;

    public static AbstractBridge getBridge() {
        return bridgeInstance;
    }

    public static void setBridge(AbstractBridge bridge) {
        bridgeInstance = bridge;
    }

    public static void atEnter(Class clazz, Object target, String methodName, String methodDesc, Object[] args) {
        bridgeInstance.atEnter(clazz, target, methodName, methodDesc, args);
    }

    public static void atExit(Class clazz, Object target, String methodName, String methodDesc, Object[] args, Object returnObject) {
        bridgeInstance.atExit(clazz, target, methodName, methodDesc, args, returnObject);
    }

    public static void atExceptionExit(Class clazz, Object target, String methodName, String methodDesc, Object[] args, Throwable throwable) {
        bridgeInstance.atExceptionExit(clazz, target, methodName, methodDesc, args, throwable);
    }

    public static abstract class AbstractBridge {
        public abstract void atEnter(Class clazz, Object target, String methodName, String methodDesc, Object[] args);

        public abstract void atExit(Class clazz, Object target, String methodName, String methodDesc, Object[] args, Object returnObject);

        public abstract void atExceptionExit(Class clazz, Object target, String methodName, String methodDesc, Object[] args, Throwable throwable);
    }

    static class NopBridge extends AbstractBridge {

        @Override
        public void atEnter(Class clazz, Object target, String methodName, String methodDesc, Object[] args) {
            // NopBridge do not need to do anything
        }

        @Override
        public void atExit(Class clazz, Object target, String methodName, String methodDesc, Object[] args, Object returnObject) {
            // NopBridge do not need to do anything
        }

        @Override
        public void atExceptionExit(Class clazz, Object target, String methodName, String methodDesc, Object[] args, Throwable throwable) {
            // NopBridge do not need to do anything
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy