ObservableZooKeeperServer.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Copyright 2008, Yahoo! Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.zookeeper.server;
  17. import java.io.File;
  18. import java.io.IOException;
  19. /**
  20. * The observable server broadcast notifications when its state changes.
  21. *
  22. * The code interested in receiving the notification must implement
  23. * the {@link ServerObserver} interface and register the instance with
  24. * {@link ObserverManager}.
  25. */
  26. public class ObservableZooKeeperServer extends ZooKeeperServer{
  27. private ZooKeeperObserverNotifier notifier=new ZooKeeperObserverNotifier(this);
  28. public ObservableZooKeeperServer(File dataDir, File dataLogDir,
  29. int tickTime,DataTreeBuilder treeBuilder) throws IOException {
  30. super(dataDir, dataLogDir, tickTime,treeBuilder);
  31. }
  32. public ObservableZooKeeperServer(DataTreeBuilder treeBuilder) throws IOException {
  33. super(treeBuilder);
  34. }
  35. public void shutdown() {
  36. notifier.notifyShutdown();
  37. super.shutdown();
  38. }
  39. public void startup() throws IOException, InterruptedException {
  40. super.startup();
  41. notifier.notifyStarted();
  42. }
  43. }