sofastack / sofa-rpc

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework.
https://www.sofastack.tech/sofa-rpc/docs/Home
Apache License 2.0
3.81k stars 1.17k forks source link

code cleanup for Destroyable #1292

Closed JoeCqupt closed 1 year ago

JoeCqupt commented 1 year ago

Motivation:

code cleanup

base class Registry already implemented method destroy(DestroyHook hook)

Modification:

remove override method destroy(DestroyHook hook) for ConsulRegistry & ZookeeperRegistry

Result:

JoeCqupt commented 1 year ago

discussion: make method Destroyable#destroy(DestroyHook hook) be a default method ???

public interface Destroyable {

    public void destroy();

    default void destroy(DestroyHook hook){
        if (hook != null) {
            hook.preDestroy();
        }
        destroy();
        if (hook != null) {
            hook.postDestroy();
        }
    }

    interface DestroyHook {

        public void preDestroy();

        public void postDestroy();
    }
}