exceptionfactory commented on code in PR #6040: URL: https://github.com/apache/nifi/pull/6040#discussion_r873943649
########## nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/main/java/org/apache/nifi/distributed/cache/server/EventCacheServer.java: ########## @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.distributed.cache.server; + +import org.apache.nifi.event.transport.EventServer; +import org.apache.nifi.event.transport.configuration.ShutdownQuietPeriod; +import org.apache.nifi.event.transport.configuration.ShutdownTimeout; +import org.apache.nifi.event.transport.configuration.TransportProtocol; +import org.apache.nifi.event.transport.netty.NettyEventServerFactory; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.security.util.ClientAuth; + +import javax.net.ssl.SSLContext; +import java.net.InetAddress; +import java.util.Objects; + +/** + * Abstract Event Cache Server with standard lifecycle methods + */ +public abstract class EventCacheServer implements CacheServer { + private static final InetAddress ALL_ADDRESSES = null; + + private final ComponentLog log; + + private final int port; + + private EventServer eventServer; + + public EventCacheServer( + final ComponentLog log, + final int port + ) { + this.log = Objects.requireNonNull(log, "Component Log required"); + this.port = port; + } + + /** + * Start Server + * + */ + @Override + public void start() { + eventServer = createEventServer(); + log.info("Started Cache Server Port [{}]", port); + } + + /** + * Stop Server + * + */ + @Override + public void stop() { + if (eventServer == null) { + log.info("Server not running"); + } else { + eventServer.shutdown(); + } + + log.info("Stopped Cache Server Port [{}]", port); + } + + /** + * Get Server Port Number + * + * @return Port Number + */ + @Override + public int getPort() { + return port; + } + + /** + * Create Event Server Factory with standard properties + * + * @param identifier Component Identifier + * @param sslContext SSL Context is null when not configured + * @return Netty Event Server Factory + */ + protected NettyEventServerFactory createEventServerFactory(final String identifier, final SSLContext sslContext) { + final NettyEventServerFactory eventServerFactory = new NettyEventServerFactory(ALL_ADDRESSES, port, TransportProtocol.TCP); + eventServerFactory.setSslContext(sslContext); + eventServerFactory.setClientAuth(ClientAuth.REQUIRED); Review Comment: Yes, the current implementation requires client authentication when enabling TLS. This could be changed to make client authentication configurable using a new property, but it seems best to address that in a separate issue. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
