io.micronaut.runtime.server.EmbeddedServer Java Examples
The following examples show how to use
io.micronaut.runtime.server.EmbeddedServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GrpcEmbeddedServer.java From micronaut-grpc with Apache License 2.0 | 6 votes |
@Override public EmbeddedServer stop() { if (running.compareAndSet(true, false)) { try { eventPublisher.publishEvent(new ServerShutdownEvent(this)); if (serviceInstance != null) { applicationContext.publishEvent(new ServiceStoppedEvent(serviceInstance)); } } finally { server.shutdownNow(); } } return this; }
Example #2
Source File: GrpcServerInstance.java From micronaut-grpc with Apache License 2.0 | 6 votes |
/** * Default constructor. * @param embeddedServer The embedded server * @param id The ID * @param uri The URI * @param metadata The metadata * @param metadataContributors The metadata contributors */ GrpcServerInstance( EmbeddedServer embeddedServer, String id, URI uri, @Nullable Map<String, String> metadata, @javax.annotation.Nullable List<ServiceInstanceMetadataContributor> metadataContributors) { this.embeddedServer = embeddedServer; this.id = id; this.uri = uri; if (metadata == null) { metadata = new LinkedHashMap<>(5); } if (CollectionUtils.isNotEmpty(metadataContributors)) { for (ServiceInstanceMetadataContributor contributor : metadataContributors) { contributor.contribute(this, metadata); } } this.metadata = ConvertibleValues.of(metadata); }
Example #3
Source File: GrpcEmbeddedServer.java From micronaut-grpc with Apache License 2.0 | 6 votes |
@Override public EmbeddedServer stop() { if (running.compareAndSet(true, false)) { try { eventPublisher.publishEvent(new ServerShutdownEvent(this)); if (serviceInstance != null) { applicationContext.publishEvent(new ServiceStoppedEvent(serviceInstance)); } } finally { server.shutdownNow(); } } return this; }
Example #4
Source File: GrpcServerInstance.java From micronaut-grpc with Apache License 2.0 | 6 votes |
/** * Default constructor. * @param embeddedServer The embedded server * @param id The ID * @param uri The URI * @param metadata The metadata * @param metadataContributors The metadata contributors */ GrpcServerInstance( EmbeddedServer embeddedServer, String id, URI uri, @Nullable Map<String, String> metadata, @javax.annotation.Nullable List<ServiceInstanceMetadataContributor> metadataContributors) { this.embeddedServer = embeddedServer; this.id = id; this.uri = uri; if (metadata == null) { metadata = new LinkedHashMap<>(5); } if (CollectionUtils.isNotEmpty(metadataContributors)) { for (ServiceInstanceMetadataContributor contributor : metadataContributors) { contributor.contribute(this, metadata); } } this.metadata = ConvertibleValues.of(metadata); }
Example #5
Source File: LocalFunctionInvokeJavaSpec.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Test public void testInvokingALocalFunctionRX() { Sum sum = new Sum(); sum.setA(5); sum.setB(10); EmbeddedServer server = ApplicationContext.run(EmbeddedServer.class); RxMathClient mathClient = server.getApplicationContext().getBean(RxMathClient.class); assertEquals(Long.valueOf(Integer.MAX_VALUE), mathClient.max().blockingGet()); assertEquals(2, mathClient.rnd(1.6f).blockingGet().longValue()); assertEquals(15, mathClient.sum(sum).blockingGet().longValue()); }
Example #6
Source File: GrpcEmbeddedServer.java From micronaut-grpc with Apache License 2.0 | 5 votes |
@Override public EmbeddedServer start() { if (running.compareAndSet(false, true)) { try { server.start(); eventPublisher.publishEvent(new ServerStartupEvent(this)); getApplicationConfiguration().getName().ifPresent(id -> { Map<String, String> metadata = new LinkedHashMap<>(); if (computeInstanceMetadataResolver != null) { final Optional<ComputeInstanceMetadata> cim = computeInstanceMetadataResolver.resolve( applicationContext.getEnvironment() ); cim.ifPresent(computeInstanceMetadata -> metadata.putAll(computeInstanceMetadata.getMetadata())); } this.serviceInstance = new GrpcServerInstance( this, id, getURI(), metadata, metadataContributors ); applicationContext.publishEvent(new ServiceReadyEvent(serviceInstance)); }); } catch (IOException e) { throw new ApplicationStartupException("Unable to start GRPC server: " + e.getMessage(), e); } } return this; }
Example #7
Source File: LocalFunctionInvokeJavaSpec.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Test public void testInvokingALocalFunction() { Sum sum = new Sum(); sum.setA(5); sum.setB(10); EmbeddedServer server = ApplicationContext.run(EmbeddedServer.class); MathClient mathClient = server.getApplicationContext().getBean(MathClient.class); assertEquals(Long.valueOf(Integer.MAX_VALUE), mathClient.max()); assertEquals(2, mathClient.rnd(1.6f)); assertEquals(15, mathClient.sum(sum)); }
Example #8
Source File: GrpcEmbeddedServerListener.java From micronaut-grpc with Apache License 2.0 | 5 votes |
@Override public void onApplicationEvent(ServerStartupEvent event) { final EmbeddedServer server = event.getSource(); if (!(server instanceof GrpcEmbeddedServer)) { this.grpcServer = beanContext.getBean(GrpcEmbeddedServer.class); grpcServer.start(); if (LOG.isInfoEnabled()) { LOG.info("GRPC started on port {}", grpcServer.getPort()); } } }
Example #9
Source File: ConditionalOnWebApplicationAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder(Requires.class) .member("beans", new AnnotationClassValue<>(EmbeddedServer.class)) .build() ); }
Example #10
Source File: ConditionalOnNotWebApplicationAnnotationMapper.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder(Requires.class) .member("missingBeans", new AnnotationClassValue<>(EmbeddedServer.class)) .build() ); }
Example #11
Source File: GrpcEmbeddedServerListener.java From micronaut-grpc with Apache License 2.0 | 5 votes |
@Override public void onApplicationEvent(ServerStartupEvent event) { final EmbeddedServer server = event.getSource(); if (!(server instanceof GrpcEmbeddedServer)) { this.grpcServer = beanContext.getBean(GrpcEmbeddedServer.class); grpcServer.start(); if (LOG.isInfoEnabled()) { LOG.info("GRPC started on port {}", grpcServer.getPort()); } } }
Example #12
Source File: GrpcEmbeddedServer.java From micronaut-grpc with Apache License 2.0 | 5 votes |
@Override public EmbeddedServer start() { if (running.compareAndSet(false, true)) { try { server.start(); eventPublisher.publishEvent(new ServerStartupEvent(this)); getApplicationConfiguration().getName().ifPresent(id -> { Map<String, String> metadata = new LinkedHashMap<>(); if (computeInstanceMetadataResolver != null) { final Optional<ComputeInstanceMetadata> cim = computeInstanceMetadataResolver.resolve( applicationContext.getEnvironment() ); cim.ifPresent(computeInstanceMetadata -> metadata.putAll(computeInstanceMetadata.getMetadata())); } this.serviceInstance = new GrpcServerInstance( this, id, getURI(), metadata, metadataContributors ); applicationContext.publishEvent(new ServiceReadyEvent(serviceInstance)); }); } catch (IOException e) { throw new ApplicationStartupException("Unable to start GRPC server: " + e.getMessage(), e); } } return this; }
Example #13
Source File: GreetingClientUnitTest.java From tutorials with MIT License | 4 votes |
@Before public void setup() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().getBean(GreetingClient.class); }
Example #14
Source File: ConcreteGreetingClientUnitTest.java From tutorials with MIT License | 4 votes |
@Before public void setup() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().getBean(ConcreteGreetingClient.class); }
Example #15
Source File: GrpcServerInstance.java From micronaut-grpc with Apache License 2.0 | 4 votes |
@Override public EmbeddedServer getEmbeddedServer() { return embeddedServer; }
Example #16
Source File: PolicyControllerTest.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().createBean(PolicyTestClient.class, server.getURL()); }
Example #17
Source File: HelloControllerTest.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().createBean(HelloTestClient.class, server.getURL()); }
Example #18
Source File: PolicySearchControllerTest.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().createBean(PolicySearchTestClient.class, server.getURL()); }
Example #19
Source File: PricingControllerTest.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().createBean(PricingTestClient.class, server.getURL()); }
Example #20
Source File: GrpcServerInstance.java From micronaut-grpc with Apache License 2.0 | 4 votes |
@Override public EmbeddedServer getEmbeddedServer() { return embeddedServer; }
Example #21
Source File: HelloControllerTest.java From java-docs-samples with Apache License 2.0 | 3 votes |
@BeforeClass public static void setupServer() { server = ApplicationContext.run(EmbeddedServer.class); client = server.getApplicationContext().createBean(HttpClient.class, server.getURL()); }