Java 类com.google.common.util.concurrent.Service.Listener 实例源码

项目:guava-mock    文件:AbstractServiceTest.java   
/**
 * This tests for a bug where if {@link Service#stopAsync()} was called while the service was
 * {@link State#STARTING} more than once, the {@link Listener#stopping(State)} callback would get
 * called multiple times.
 */
public void testManualServiceStopMultipleTimesWhileStarting() throws Exception {
  ManualSwitchedService service = new ManualSwitchedService();
  final AtomicInteger stopppingCount = new AtomicInteger();
  service.addListener(new Listener() {
    @Override public void stopping(State from) {
      stopppingCount.incrementAndGet();
    }
  }, directExecutor());

  service.startAsync();
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
}
项目:guava-mock    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(new Listener() {
    @Override public void terminated(State from) {
      service.stopAsync().awaitTerminated();
    }
  }, directExecutor());
  service.startAsync().awaitRunning();

  Thread thread = new Thread() {
    @Override public void run() {
      service.stopAsync().awaitTerminated();
    }
  };
  thread.start();
  thread.join(LONG_TIMEOUT_MILLIS);
  assertFalse(thread + " is deadlocked", thread.isAlive());
}
项目:googles-monorepo-demo    文件:AbstractServiceTest.java   
/**
 * This tests for a bug where if {@link Service#stopAsync()} was called while the service was
 * {@link State#STARTING} more than once, the {@link Listener#stopping(State)} callback would get
 * called multiple times.
 */
public void testManualServiceStopMultipleTimesWhileStarting() throws Exception {
  ManualSwitchedService service = new ManualSwitchedService();
  final AtomicInteger stopppingCount = new AtomicInteger();
  service.addListener(new Listener() {
    @Override public void stopping(State from) {
      stopppingCount.incrementAndGet();
    }
  }, directExecutor());

  service.startAsync();
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
}
项目:googles-monorepo-demo    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(new Listener() {
    @Override public void terminated(State from) {
      service.stopAsync().awaitTerminated();
    }
  }, directExecutor());
  service.startAsync().awaitRunning();

  Thread thread = new Thread() {
    @Override public void run() {
      service.stopAsync().awaitTerminated();
    }
  };
  thread.start();
  thread.join(LONG_TIMEOUT_MILLIS);
  assertFalse(thread + " is deadlocked", thread.isAlive());
}
项目:guava-libraries    文件:AbstractServiceTest.java   
/**
 * This tests for a bug where if {@link Service#stopAsync()} was called while the service was
 * {@link State#STARTING} more than once, the {@link Listener#stopping(State)} callback would get
 * called multiple times.
 */
public void testManualServiceStopMultipleTimesWhileStarting() throws Exception {
  ManualSwitchedService service = new ManualSwitchedService();
  final AtomicInteger stopppingCount = new AtomicInteger();
  service.addListener(new Listener() {
    @Override public void stopping(State from) {
      stopppingCount.incrementAndGet();
    }
  }, directExecutor());

  service.startAsync();
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
}
项目:guava-libraries    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(new Listener() {
    @Override public void terminated(State from) {
      service.stopAsync().awaitTerminated();
    }
  }, directExecutor());
  service.startAsync().awaitRunning();

  Thread thread = new Thread() {
    @Override public void run() {
      service.stopAsync().awaitTerminated();
    }
  };
  thread.start();
  thread.join(LONG_TIMEOUT_MILLIS);
  assertFalse(thread + " is deadlocked", thread.isAlive());
}
项目:guava    文件:AbstractServiceTest.java   
/**
 * This tests for a bug where if {@link Service#stopAsync()} was called while the service was
 * {@link State#STARTING} more than once, the {@link Listener#stopping(State)} callback would get
 * called multiple times.
 */
public void testManualServiceStopMultipleTimesWhileStarting() throws Exception {
  ManualSwitchedService service = new ManualSwitchedService();
  final AtomicInteger stopppingCount = new AtomicInteger();
  service.addListener(
      new Listener() {
        @Override
        public void stopping(State from) {
          stopppingCount.incrementAndGet();
        }
      },
      directExecutor());

  service.startAsync();
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
}
项目:guava    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(
      new Listener() {
        @Override
        public void terminated(State from) {
          service.stopAsync().awaitTerminated();
        }
      },
      directExecutor());
  service.startAsync().awaitRunning();

  Thread thread =
      new Thread() {
        @Override
        public void run() {
          service.stopAsync().awaitTerminated();
        }
      };
  thread.start();
  thread.join(LONG_TIMEOUT_MILLIS);
  assertFalse(thread + " is deadlocked", thread.isAlive());
}
项目:guava    文件:AbstractServiceTest.java   
/**
 * This tests for a bug where if {@link Service#stopAsync()} was called while the service was
 * {@link State#STARTING} more than once, the {@link Listener#stopping(State)} callback would get
 * called multiple times.
 */
public void testManualServiceStopMultipleTimesWhileStarting() throws Exception {
  ManualSwitchedService service = new ManualSwitchedService();
  final AtomicInteger stopppingCount = new AtomicInteger();
  service.addListener(
      new Listener() {
        @Override
        public void stopping(State from) {
          stopppingCount.incrementAndGet();
        }
      },
      directExecutor());

  service.startAsync();
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
  service.stopAsync();
  assertEquals(1, stopppingCount.get());
}
项目:guava    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(
      new Listener() {
        @Override
        public void terminated(State from) {
          service.stopAsync().awaitTerminated();
        }
      },
      directExecutor());
  service.startAsync().awaitRunning();

  Thread thread =
      new Thread() {
        @Override
        public void run() {
          service.stopAsync().awaitTerminated();
        }
      };
  thread.start();
  thread.join(LONG_TIMEOUT_MILLIS);
  assertFalse(thread + " is deadlocked", thread.isAlive());
}
项目:TakinRPC    文件:RPCServer.java   
/**
 * 启动过滤器
 * 启动注册服务
 * 启动服务 
 * 
 * @throws Exception
 */
public void start() throws Exception {
    GuiceDI.getInstance(ServerRegistry.class).startAsync().addListener(new Listener() {
        @Override
        public void running() {
            logger.info("zk registry running");
        }
    }, MoreExecutors.directExecutor());
    GuiceDI.getInstance(RemotingNettyServer.class).startAsync().awaitRunning();
}
项目:TakinRPC    文件:RPCServer.java   
public void shutdown() {
    GuiceDI.getInstance(ServerRegistry.class).stopAsync();
    GuiceDI.getInstance(RemotingNettyServer.class).stopAsync().addListener(new Listener() {

        @Override
        public void terminated(State from) {
            super.terminated(from);
            logger.info("zk registry stopped");
        }
    }, MoreExecutors.directExecutor());
}
项目:guava-mock    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(new Listener() {
    @Override public void running() {
      service.awaitRunning();
    }
  }, directExecutor());
  service.startAsync().awaitRunning(LONG_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  service.stopAsync();
}
项目:googles-monorepo-demo    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(new Listener() {
    @Override public void running() {
      service.awaitRunning();
    }
  }, directExecutor());
  service.startAsync().awaitRunning(LONG_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  service.stopAsync();
}
项目:guava-libraries    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(new Listener() {
    @Override public void running() {
      service.awaitRunning();
    }
  }, directExecutor());
  service.startAsync().awaitRunning(LONG_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  service.stopAsync();
}
项目:guava    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(
      new Listener() {
        @Override
        public void running() {
          service.awaitRunning();
        }
      },
      directExecutor());
  service.startAsync().awaitRunning(LONG_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  service.stopAsync();
}
项目:guava    文件:AbstractServiceTest.java   
public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
  final NoOpThreadedService service = new NoOpThreadedService();
  service.addListener(
      new Listener() {
        @Override
        public void running() {
          service.awaitRunning();
        }
      },
      directExecutor());
  service.startAsync().awaitRunning(LONG_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  service.stopAsync();
}