com.linecorp.armeria.server.Server.addListener()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中com.linecorp.armeria.server.Server.addListener()方法的一些代码示例,展示了Server.addListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server.addListener()方法的具体详情如下:
包路径:com.linecorp.armeria.server.Server
类名称:Server
方法名:addListener

Server.addListener介绍

[英]Adds the specified ServerListener to this Server, so that it is notified when the state of this Server changes. This method is useful when you want to initialize/destroy the resources associated with a Service:

> public class MyService extends SimpleService >             } 
> 
>             @Override 
>             public void serverStopped()  
>                 ... destroy ... 
>             } 
>         } 
>     } 
> } 
}

[中]将指定的ServerListener添加到此服务器,以便在该服务器的状态更改时通知它。当您想要初始化/销毁与服务关联的资源时,此方法非常有用:

> public class MyService extends SimpleService >             } 
> 
>             @Override 
>             public void serverStopped()  
>                 ... destroy ... 
>             } 
>         } 
>     } 
> } 
}

代码示例

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  if (server != null) {
    if (server != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  server = cfg.server();
  // Auto-detect the primary port number and its session protocol after the server started.
  server.addListener(portConfigHolder);
}

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  super.serviceAdded(cfg);
  if (server != null) {
    if (server != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  server = cfg.server();
  server.addListener(serverHealthUpdater);
}

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  super.serviceAdded(cfg);
  if (server != null) {
    if (server != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  server = cfg.server();
  // Auto-detect the primary port number and its session protocol after the server started.
  server.addListener(portConfigHolder);
}

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) {
  if (armeriaServer != null) {
    if (armeriaServer != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  armeriaServer = cfg.server();
  armeriaServer.addListener(configurator);
  if (hostname == null) {
    hostname = armeriaServer.defaultHostname();
  }
}

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  super.serviceAdded(cfg);
  if (associatedServer != null) {
    if (associatedServer != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  associatedServer = cfg.server();
  associatedServer.addListener(new ServerListenerAdapter() {
    @Override
    public void serverStopped(Server server) {
      close();
    }
  });
}

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  if (hostName == null) {
    hostName = cfg.server().defaultHostname();
  }
  if (armeriaServer != null) {
    if (armeriaServer != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  armeriaServer = cfg.server();
  armeriaServer.addListener(configurator);
}

代码示例来源:origin: line/armeria

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  super.serviceAdded(cfg);
  if (server != null) {
    if (server != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  server = cfg.server();
  // Build the Specification after all the services are added to the server.
  server.addListener(new ServerListenerAdapter() {
    @Override
    public void serverStarting(Server server) throws Exception {
      final ServerConfig config = server.config();
      final List<VirtualHost> virtualHosts = config.findVirtualHosts(DocService.this);
      final List<ServiceConfig> services =
          config.serviceConfigs().stream()
             .filter(se -> virtualHosts.contains(se.virtualHost()))
             .collect(toImmutableList());
      ServiceSpecification spec = generate(services);
      spec = addDocStrings(spec, services);
      spec = addExamples(spec);
      vfs(SPECIFICATION_INDEX).setContent(jsonMapper.writerWithDefaultPrettyPrinter()
                             .writeValueAsBytes(spec));
    }
  });
}

代码示例来源:origin: line/armeria

@Before
public void startServers() {
  servers = new ArrayList<>();
  for (Endpoint endpoint : sampleEndpoints) {
    final Server server = new ServerBuilder().http(endpoint.port())
                         .service("/", new EchoService())
                         .build();
    final ServerListener listener = new ZooKeeperUpdatingListenerBuilder(
        instance().connectString().get(), zNode)
        .sessionTimeoutMillis(sessionTimeoutMillis)
        .endpoint(endpoint)
        .build();
    server.addListener(listener);
    server.start().join();
    servers.add(server);
  }
}

代码示例来源:origin: line/armeria

server.addListener(rejectingListener);

代码示例来源:origin: com.linecorp.armeria/armeria-saml

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  if (server != null) {
    if (server != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  server = cfg.server();
  // Auto-detect the primary port number and its session protocol after the server started.
  server.addListener(portConfigHolder);
}

代码示例来源:origin: com.linecorp.armeria/armeria-saml

@Override
public void serviceAdded(ServiceConfig cfg) throws Exception {
  super.serviceAdded(cfg);
  if (server != null) {
    if (server != cfg.server()) {
      throw new IllegalStateException("cannot be added to more than one server");
    } else {
      return;
    }
  }
  server = cfg.server();
  // Auto-detect the primary port number and its session protocol after the server started.
  server.addListener(portConfigHolder);
}

相关文章