类org.springframework.boot.actuate.endpoint.annotation.WriteOperation源码实例Demo

下面列出了怎么用org.springframework.boot.actuate.endpoint.annotation.WriteOperation的API类实例代码及写法,或者点击链接到github查看源代码。


@WriteOperation
public Mono<String> operate(@Selector String action) {
    if ("online".equalsIgnoreCase(action)) {
        this.rsocketServiceStatus = AppStatusEvent.STATUS_SERVING;
        return sendAppStatus(this.rsocketServiceStatus).thenReturn("Succeed to register RSocket services on brokers!");
    } else if ("offline".equalsIgnoreCase(action)) {
        this.rsocketServiceStatus = AppStatusEvent.STATUS_OUT_OF_SERVICE;
        return sendAppStatus(this.rsocketServiceStatus).thenReturn("Succeed to unregister RSocket services on brokers!");
    } else if ("shutdown".equalsIgnoreCase(action)) {
        this.rsocketServiceStatus = AppStatusEvent.STATUS_STOPPED;
        return sendAppStatus(this.rsocketServiceStatus)
                .thenReturn("Succeed to unregister RSocket services on brokers! Please wait almost 60 seconds to shutdown the Spring Boot App!");
    } else if ("refreshUpstreams".equalsIgnoreCase(action)) {
        Collection<UpstreamCluster> allClusters = this.upstreamManager.findAllClusters();
        for (UpstreamCluster upstreamCluster : allClusters) {
            upstreamCluster.getLoadBalancedRSocket().refreshUnHealthyUris();
        }
        return Mono.just("Begin to refresh unHealthy upstream clusters now!");
    } else {
        return Mono.just("Unknown action, please use online, offline and shutdown");
    }
}
 

@Autowired
EndpointCommand(ApplicationContext appCtx) {
    appCtx.getBeansWithAnnotation(Endpoint.class).entrySet().stream()
            .sorted(Comparator.comparing(e -> e.getKey()))
            .forEachOrdered(entry -> {
                log.debug("{} : {}", entry.getKey(), entry.getValue().getClass().getName());
                for (Method m : entry.getValue().getClass().getDeclaredMethods()) {
                    if (m.isAnnotationPresent(ReadOperation.class) || m.isAnnotationPresent(WriteOperation.class)) {
                        log.debug("\tOp: {}", m.getName());
                        for (Parameter p : m.getParameters()) {
                            log.debug("\t\tParameter {}, {}", p.getName(), p.getType().getName());
                        }
                    }
                }
            });
}
 

@WriteOperation
public CircuitBreakerUpdateStateResponse updateCircuitBreakerState(@Selector String name, UpdateState updateState) {
    final CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(name);
    final String message = "%s state has been changed successfully";
    switch (updateState) {
        case CLOSE:
            circuitBreaker.transitionToClosedState();
            return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), String.format(message, name));
        case FORCE_OPEN:
            circuitBreaker.transitionToForcedOpenState();
            return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), String.format(message, name));
        case DISABLE:
            circuitBreaker.transitionToDisabledState();
            return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), String.format(message, name));
        default:
            return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), "State change value is not supported please use only " + Arrays.toString(UpdateState.values()));
    }

}
 

@WriteOperation
public void changeState(@Selector String name, State state) {
	Binding<?> binding = BindingsEndpoint.this.locateBinding(name);
	if (binding != null) {
		switch (state) {
		case STARTED:
			binding.start();
			break;
		case STOPPED:
			binding.stop();
			break;
		case PAUSED:
			binding.pause();
			break;
		case RESUMED:
			binding.resume();
			break;
		default:
			break;
		}
	}
}
 
源代码5 项目: genie   文件: LeaderElectionActuator.java

/**
 * Forces the node to leave the leader election, then re-join it.
 *
 * @param action the action to perform
 */
@WriteOperation
public void doAction(final Action action) {
    switch (action) {
        case START:
            log.info("Starting leader election service");
            this.clusterLeaderService.start();
            break;
        case STOP:
            log.info("Stopping leader election service");
            this.clusterLeaderService.stop();
            break;
        case RESTART:
            log.info("Restarting leader election service");
            this.clusterLeaderService.stop();
            this.clusterLeaderService.start();
            break;
        default:
            log.error("Unknown action: " + action);
            throw new UnsupportedOperationException("Unknown action: " + action.name());
    }
}
 
源代码6 项目: Cleanstone   文件: ConsoleEndpoint.java

@WriteOperation
public void sendCommand(String commandString) {
    log.info("WebConsole: " + commandString + "");

    CommandMessage commandMessage = CommandMessageFactory.construct(consoleSender, commandString, this.commandRegistry);

    Command command = commandRegistry.getCommand(commandMessage.getCommandName());
    if (command != null) {
        try {
            command.execute(commandMessage);
        } catch (Exception e) {
            log.error("Error executing Command: []", e);
        }
    }
}
 

@WriteOperation
public String toggleLatencyAssault() {
  this.chaosMonkeySettings
      .getAssaultProperties()
      .setLatencyActive(!this.getAssaultProperties().getLatencyActive());
  return String.valueOf(this.getAssaultProperties().getLatencyActive());
}
 

@WriteOperation
public String toggleExceptionAssault() {
  this.chaosMonkeySettings
      .getAssaultProperties()
      .setExceptionsActive(!this.getAssaultProperties().getExceptionsActive());
  return String.valueOf(this.getAssaultProperties().getExceptionsActive());
}
 

@WriteOperation
public String toggleKillApplicationAssault() {
  this.chaosMonkeySettings
      .getAssaultProperties()
      .setKillApplicationActive(!this.getAssaultProperties().getKillApplicationActive());
  return String.valueOf(this.getAssaultProperties().getKillApplicationActive());
}
 

@WriteOperation
@Nullable
public CircuitBreakerView transitionTo(@Selector final String name, final CircuitBreaker.State state) {
    final CircuitBreaker breaker = breakers.get(name);

    if (breaker == null) {
        return null;
    }

    transitioner(state).accept(breaker);

    return toView(breaker);
}
 

@WriteOperation
public void busEnvWithDestination(String name, String value,
		@Selector String destination) { // TODO: document params
	Map<String, String> params = Collections.singletonMap(name, value);
	publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(),
			destination, params));
}
 

@WriteOperation
public Object restart() {
	Thread thread = new Thread(this::safeRestart);
	thread.setDaemon(false);
	thread.start();
	return Collections.singletonMap("message", "Restarting");
}
 

@WriteOperation
public Boolean pause() {
	if (isRunning()) {
		doPause();
		return true;
	}
	return false;
}
 

@WriteOperation
public Boolean resume() {
	if (!isRunning()) {
		doResume();
		return true;
	}
	return false;
}
 

@WriteOperation
public ResponseEntity<?> setStatus(String status) {
	Assert.notNull(status, "status may not by null");

	if (this.registration == null) {
		return ResponseEntity.status(HttpStatus.NOT_FOUND)
				.body("no registration found");
	}

	this.serviceRegistry.setStatus(this.registration, status);
	return ResponseEntity.ok().build();
}
 

@WriteOperation
public List<Note> addNote(String text) {
  notes.add(new Note(text));
  return notes;
}
 

@WriteOperation
public List<Note> addNote(String text) {
  notes.add(new Note(text));
  return notes;
}
 

@WriteOperation
public List<Note> addNote(String text) {
  notes.add(new Note(text));
  return notes;
}
 

@WriteOperation
public List<Note> addNote(String text) {
  notes.add(new Note(text));
  return notes;
}
 

@WriteOperation
public boolean initializeTraderAggregates()
        throws InterruptedException, ExecutionException {
  if (hasData()) {
    logger.warn("#### The Event Store already contains events. Aborting initialization...");
    return true;
  }
  logger.info("#### The Event Store does not contain any events. "
          + "Starting initialization of Trader Aggregates.");

  CommandMessage<Object> canary = asCommandMessage(new CreatePortfolioCommand(new PortfolioId(), new UserId()));
  if (!commandRouter.findDestination(canary).isPresent()) {
    logger.error("Trading-Engine isn't running. Unable to initialize data");
    return false;
  }

  logger.info("Adding some companies to the application...");
  CompanyId pivotalId = new CompanyId();
  CompanyId axonIQId = new CompanyId();
  CompanyId solsticeId = new CompanyId();
  commandGateway.sendAndWait(new CreateCompanyCommand(pivotalId, "Pivotal", 100000000, 1000000));
  commandGateway.sendAndWait(new CreateCompanyCommand(axonIQId, "AxonIQ", 100000000, 1000000));
  commandGateway.sendAndWait(new CreateCompanyCommand(solsticeId, "Solstice", 100000000, 1000000));

  logger.info("Adding some users to the application...");
  UserId allard = createUser("Allard", "allard");
  UserId steven = createUser("Steven", "steven");
  UserId ben = createUser("Ben", "ben");
  UserId pieter = createUser("Pieter", "pieter");
  UserId sampath = createUser("Sampath", "sampath");
  UserId haridu = createUser("Haridu", "haridu");
  UserId jakub = createUser("Jakub", "jakub");
  UserId kenny = createUser("Kenny", "kenny");
  UserId david = createUser("David", "david");

  logger.info("Giving each user a starting position...");
  addMoney(allard, 100000);
  addItems(allard, axonIQId, 10000L);

  addMoney(steven, 100000);
  addItems(steven, axonIQId, 10000L);

  addMoney(ben, 100000);
  addItems(ben, pivotalId, 10000L);

  addMoney(pieter, 100000);
  addItems(pieter, pivotalId, 10000L);

  addMoney(sampath, 100000);
  addItems(sampath, solsticeId, 10000L);

  addMoney(haridu, 100000);
  addItems(haridu, solsticeId, 10000L);

  addMoney(jakub, 100000);
  addItems(jakub, pivotalId, 10000L);

  addMoney(kenny, 100000);
  addItems(kenny, pivotalId, 10000L);

  addMoney(david, 100000);
  addItems(david, pivotalId, 10000L);

  logger.info("All done. Data initialisation is complete.");

  return true;
}
 

@WriteOperation
public void set(String message) {
    LOGGER.info("Custom Endpoint Message {}", message);
}
 

@WriteOperation
public Map<String, Object> shutdown() throws Exception {
    return dubboShutdownMetadata.shutdown();
}
 

@WriteOperation
public String enableChaosMonkey() {
  this.chaosMonkeySettings.getChaosMonkeyProperties().setEnabled(true);
  return "Chaos Monkey is enabled";
}
 

@WriteOperation
public String disableChaosMonkey() {
  this.chaosMonkeySettings.getChaosMonkeyProperties().setEnabled(false);
  return "Chaos Monkey is disabled";
}
 

@WriteOperation
public void releaseLock(@Selector final String id) {
    this.lightminServerLockManager.releaseLock(id, Boolean.TRUE);
}
 

@WriteOperation
public void busRefreshWithDestination(@Selector String destination) {
	publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), destination));
}
 

@WriteOperation
public void busRefresh() {
	publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), null));
}
 

@WriteOperation
public void busEnv(String name, String value) { // TODO: document params
	Map<String, String> params = Collections.singletonMap(name, value);
	publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), null,
			params));
}
 

@WriteOperation
public Object write(String name, String value) {
	this.environment.setProperty(name, value);
	return Collections.singletonMap(name, value);
}
 

@WriteOperation
public Collection<String> refresh() {
	Set<String> keys = this.contextRefresher.refresh();
	return keys;
}
 
 类所在包
 同包方法