コード例 #1
0
  @PostConstruct
  private void start() throws IOException {
    logger.info("starting redis...");

    redisServer.start();

    logger.info(
        String.format(
            "redis listen ports: %s",
            redisServer
                .ports()
                .stream()
                .map(port -> port.toString())
                .collect(Collectors.joining(","))));
  }
コード例 #2
0
ファイル: ClusterMaster.java プロジェクト: 3rdstage/exercise
  @Override
  public ActorSystem buildActorSystem(Config config) throws Exception {

    // start redis
    final int redisPort =
        (config.hasPath("components.redis.port"))
            ? config.getInt("components.redis.port")
            : RedisURI.DEFAULT_REDIS_PORT;
    final String redisLogLevel =
        config.hasPath("components.redis.log-level")
            ? config.getString("components.redis.log-level")
            : "verbose";
    String logBase = System.getenv("LOG_BASE");
    if (StringUtils.isBlank(logBase)) logBase = System.getenv("TEMP");
    final String redisLogFile =
        config.hasPath("components.redis.log-file")
            ? config.getString("components.redis.log-file")
            : logBase + "\\redis.log";
    final String redisPidFile =
        config.hasPath("components.redis.pid-file")
            ? config.getString("components.redis.pid-file")
            : logBase + "\\redis.pid";

    try {
      this.redis =
          RedisServer.builder()
              .redisExecProvider(RedisExecProvider.defaultProvider())
              .port(redisPort)
              .setting("loglevel " + redisLogLevel)
              .setting("logfile " + redisLogFile)
              .setting("pidfile " + redisPidFile)
              .build();
    } catch (Exception ex) {
      this.logger.error("Fail to build redis server.", ex);
      throw new IllegalStateException("Fail to build redis server.", ex);
    }
    new Thread() {
      @Override
      public void run() {
        try {
          redis.start();
          logger.info("Started redis server on {} port", redisPort);
        } catch (Exception ex) {
          logger.error("Fail to start redis server.", ex);
          // @TODO Use future to stop the actor system at this point.
        }
      }
    }.start();

    // create redis client
    String redisUri = "redis://" + this.getAddress().getHostAddress() + ":" + redisPort + "/0";
    this.redisClient = new RedisClient(RedisURI.create(redisUri));

    ActorSystem system = ActorSystem.create(this.getClusterName(), config);
    Camel camel = CamelExtension.get(system);

    this.baseUrl =
        "http://"
            + this.getAddress().getHostAddress()
            + ":"
            + this.getHttpPort()
            + "/"
            + this.getApplicationName();
    String uri = "jetty:" + this.baseUrl;

    String recorderKeyBase = this.getClusterName() + ":" + "words";
    ActorRef recordingService =
        system.actorOf(
            Props.create(RecordingService.class, recorderKeyBase, this.redisClient),
            "recorderService");

    String tracerKey = this.getClusterName() + ":trace:node:1";
    ActorRef traceLogService =
        system.actorOf(
            Props.create(TraceLogService.class, tracerKey, this.redisClient, this.jacksonMapper),
            "traceLogService");

    ActorRef analysisService =
        system.actorOf(
            Props.create(AnalysisService.class, recordingService, traceLogService),
            "analysisService");

    String pathBase =
        "akka.tcp://" + this.getClusterName() + "@" + this.getAddress().getHostAddress() + ":";
    SimpleRoutingMap<String> routingMap = new SimpleRoutingMap<String>();
    routingMap.putPath(new Key<String>("2551"), pathBase + "2551/user/analysisService");
    routingMap.putPath(new Key<String>("2552"), pathBase + "2552/user/analysisService");

    ActorRef httpClerk =
        system.actorOf(Props.create(WebService.class, uri, routingMap), "httpClerk");

    Future<ActorRef> activationFuture =
        camel.activationFutureFor(
            httpClerk, new Timeout(Duration.create(10, TimeUnit.SECONDS)), system.dispatcher());

    return system;
  }
コード例 #3
0
 @PreDestroy
 public void stop() {
   redisServer.stop();
 }
 @After
 public void teardown() {
   redisServer.stop();
 }
  @Before
  public void setup() throws Exception {

    redisServer = new RedisServer(6379);
    redisServer.start();
  }
コード例 #6
0
ファイル: RedisConfig.java プロジェクト: p-ledenev/MobileBank
 @Bean
 public JedisConnectionFactory connectionFactory() throws IOException {
   redisServer = new RedisServer(Protocol.DEFAULT_PORT);
   redisServer.start();
   return new JedisConnectionFactory();
 }