From 686ac311c9241ce64b0b6a942f95941f94446a81 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Thu, 13 Jun 2013 17:49:14 +0000 Subject: [PATCH] YARN-746. Renamed Service.register() and Service.unregister() to registerServiceListener() & unregisterServiceListener() respectively. Contributed by Steve Loughran. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1492780 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 4 +++ .../hadoop/yarn/service/AbstractService.java | 4 +-- .../hadoop/yarn/service/FilterService.java | 8 +++--- .../apache/hadoop/yarn/service/Service.java | 11 +++++--- .../yarn/service/TestServiceLifecycle.java | 26 +++++++++---------- .../containermanager/AuxServices.java | 4 +-- .../ContainerManagerImpl.java | 4 +-- 7 files changed, 34 insertions(+), 27 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 89ba261eeac..d99c6ef442d 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -136,6 +136,10 @@ Release 2.1.0-beta - UNRELEASED robust subclassing and migrated yarn-common services. (Steve Loughran via vinodkv) + YARN-746. Renamed Service.register() and Service.unregister() to + registerServiceListener() & unregisterServiceListener() respectively. + (Steve Loughran via vinodkv) + NEW FEATURES YARN-482. FS: Extend SchedulingMode to intermediate queues. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/AbstractService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/AbstractService.java index fc35f1c7c28..93a7b8dbe82 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/AbstractService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/AbstractService.java @@ -353,12 +353,12 @@ public abstract class AbstractService implements Service { } @Override - public void register(ServiceStateChangeListener l) { + public void registerServiceListener(ServiceStateChangeListener l) { listeners.add(l); } @Override - public void unregister(ServiceStateChangeListener l) { + public void unregisterServiceListener(ServiceStateChangeListener l) { listeners.remove(l); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/FilterService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/FilterService.java index 07aafaf6ef1..a67e1d0f223 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/FilterService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/FilterService.java @@ -54,13 +54,13 @@ public class FilterService implements Service { } @Override - public void register(ServiceStateChangeListener listener) { - service.register(listener); + public void registerServiceListener(ServiceStateChangeListener listener) { + service.registerServiceListener(listener); } @Override - public void unregister(ServiceStateChangeListener listener) { - service.unregister(listener); + public void unregisterServiceListener(ServiceStateChangeListener listener) { + service.unregisterServiceListener(listener); } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/Service.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/Service.java index 1749bf9bfaa..b8b99830adc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/Service.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/service/Service.java @@ -129,16 +129,19 @@ public interface Service extends Closeable { void close() throws IOException; /** - * Register an instance of the service state change events. + * Register a listener to the service state change events. + * If the supplied listener is already listening to this service, + * this method is a no-op. * @param listener a new listener */ - void register(ServiceStateChangeListener listener); + void registerServiceListener(ServiceStateChangeListener listener); /** - * Unregister a previously instance of the service state change events. + * Unregister a previously registered listener of the service state + * change events. No-op if the listener is already unregistered. * @param listener the listener to unregister. */ - void unregister(ServiceStateChangeListener listener); + void unregisterServiceListener(ServiceStateChangeListener listener); /** * Get the name of this service. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/service/TestServiceLifecycle.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/service/TestServiceLifecycle.java index bd73a41102b..472ed8b50d3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/service/TestServiceLifecycle.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/service/TestServiceLifecycle.java @@ -186,7 +186,7 @@ public class TestServiceLifecycle extends ServiceAssert { @Test public void testStopFailingInitAndStop() throws Throwable { BreakableService svc = new BreakableService(true, false, true); - svc.register(new LoggingStateChangeListener()); + svc.registerServiceListener(new LoggingStateChangeListener()); try { svc.init(new Configuration()); fail("Expected a failure, got " + svc); @@ -220,7 +220,7 @@ public class TestServiceLifecycle extends ServiceAssert { public void testServiceNotifications() throws Throwable { BreakableService svc = new BreakableService(false, false, false); BreakableStateChangeListener listener = new BreakableStateChangeListener(); - svc.register(listener); + svc.registerServiceListener(listener); svc.init(new Configuration()); assertEventCount(listener, 1); svc.start(); @@ -239,10 +239,10 @@ public class TestServiceLifecycle extends ServiceAssert { public void testServiceNotificationsStopOnceUnregistered() throws Throwable { BreakableService svc = new BreakableService(false, false, false); BreakableStateChangeListener listener = new BreakableStateChangeListener(); - svc.register(listener); + svc.registerServiceListener(listener); svc.init(new Configuration()); assertEventCount(listener, 1); - svc.unregister(listener); + svc.unregisterServiceListener(listener); svc.start(); assertEventCount(listener, 1); svc.stop(); @@ -267,12 +267,12 @@ public class TestServiceLifecycle extends ServiceAssert { new SelfUnregisteringBreakableStateChangeListener(); BreakableStateChangeListener l2 = new BreakableStateChangeListener(); - svc.register(listener); - svc.register(l2); + svc.registerServiceListener(listener); + svc.registerServiceListener(l2); svc.init(new Configuration()); assertEventCount(listener, 1); assertEventCount(l2, 1); - svc.unregister(listener); + svc.unregisterServiceListener(listener); svc.start(); assertEventCount(listener, 1); assertEventCount(l2, 2); @@ -287,7 +287,7 @@ public class TestServiceLifecycle extends ServiceAssert { @Override public synchronized void stateChanged(Service service) { super.stateChanged(service); - service.unregister(this); + service.unregisterServiceListener(this); } } @@ -301,7 +301,7 @@ public class TestServiceLifecycle extends ServiceAssert { BreakableService svc = new BreakableService(false, false, false); BreakableStateChangeListener listener = new BreakableStateChangeListener(); listener.setFailingState(Service.STATE.STARTED); - svc.register(listener); + svc.registerServiceListener(listener); svc.init(new Configuration()); assertEventCount(listener, 1); //start this; the listener failed but this won't show @@ -326,7 +326,7 @@ public class TestServiceLifecycle extends ServiceAssert { //this tests that a listener can get notified when a service is stopped AsyncSelfTerminatingService service = new AsyncSelfTerminatingService(2000); NotifyingListener listener = new NotifyingListener(); - service.register(listener); + service.registerServiceListener(listener); service.init(new Configuration()); service.start(); assertServiceInState(service, Service.STATE.STARTED); @@ -344,7 +344,7 @@ public class TestServiceLifecycle extends ServiceAssert { public void testSelfTerminatingService() throws Throwable { SelfTerminatingService service = new SelfTerminatingService(); BreakableStateChangeListener listener = new BreakableStateChangeListener(); - service.register(listener); + service.registerServiceListener(listener); service.init(new Configuration()); assertEventCount(listener, 1); //start the service @@ -357,7 +357,7 @@ public class TestServiceLifecycle extends ServiceAssert { public void testStartInInitService() throws Throwable { Service service = new StartInInitService(); BreakableStateChangeListener listener = new BreakableStateChangeListener(); - service.register(listener); + service.registerServiceListener(listener); service.init(new Configuration()); assertServiceInState(service, Service.STATE.STARTED); assertEventCount(listener, 1); @@ -367,7 +367,7 @@ public class TestServiceLifecycle extends ServiceAssert { public void testStopInInitService() throws Throwable { Service service = new StopInInitService(); BreakableStateChangeListener listener = new BreakableStateChangeListener(); - service.register(listener); + service.registerServiceListener(listener); service.init(new Configuration()); assertServiceInState(service, Service.STATE.STOPPED); assertEventCount(listener, 1); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java index e20f44ded22..bea5e50c328 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java @@ -120,7 +120,7 @@ public class AuxServices extends AbstractService AuxiliaryService service = entry.getValue(); String name = entry.getKey(); service.start(); - service.register(this); + service.registerServiceListener(this); ByteBuffer meta = service.getMeta(); if(meta != null) { serviceMeta.put(name, meta); @@ -135,7 +135,7 @@ public class AuxServices extends AbstractService synchronized (serviceMap) { for (Service service : serviceMap.values()) { if (service.getServiceState() == Service.STATE.STARTED) { - service.unregister(this); + service.unregisterServiceListener(this); service.stop(); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/ContainerManagerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/ContainerManagerImpl.java index 6a33bf2d79b..8a34ad5d65a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/ContainerManagerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/ContainerManagerImpl.java @@ -156,7 +156,7 @@ public class ContainerManagerImpl extends CompositeService implements // Start configurable services auxiliaryServices = new AuxServices(); - auxiliaryServices.register(this); + auxiliaryServices.registerServiceListener(this); addService(auxiliaryServices); this.containersMonitor = @@ -265,7 +265,7 @@ public class ContainerManagerImpl extends CompositeService implements @Override public void serviceStop() throws Exception { if (auxiliaryServices.getServiceState() == STARTED) { - auxiliaryServices.unregister(this); + auxiliaryServices.unregisterServiceListener(this); } if (server != null) { server.stop();