com.netflix.karyon.server
Class KaryonServer

java.lang.Object
  extended by com.netflix.karyon.server.KaryonServer
All Implemented Interfaces:
java.io.Closeable

public class KaryonServer
extends java.lang.Object
implements java.io.Closeable

The core server for Karyon. This server provides all core functionality to startup a karyon server but is not useful as is, since, it does not essentially open an endpoint for clients to connect.
In order to use karyon effectively, one should use the provided extensions in karyon-extensions

If one intends to provide a custom extension the following needs to be done:

Eureka Integration

Karyon provides integration with eureka as a core component and does the necessary registration/update with eureka. In order for the integration to work, the application writer, must provide the necessary configuration for eureka client as specified in the "Configuring Eureka Client" section here The easiest way of doing so is specifying a property file with name "eureka-client.properties" in the classpath. This file must have the properties required by eureka with a prefix "eureka", eg: if you need to specify the VIP address for eureka you must specify the property "eureka.vipAddress". If you need to use a different prefix, the default prefix can be overridden by specifying the same in the property PropertyNames.EUREKA_PROPERTIES_NAME_PREFIX_PROP_NAME as a property accessible to archaius The integration with eureka can be disabled by specifying a property PropertyNames.DISABLE_EUREKA_INTEGRATION set to true and accessible to archaius

Archaius Integration

As such Archaius requires minimal integration and works out of the box however, karyon does one additional step of loading the configuration from properties file located in the classpath. The properties loading is done by calling ConfigurationManager.loadCascadedPropertiesFromResources(String) with the name of the config as returned by DeploymentContext.getApplicationId() from the deployment context configured in archaius. For the above to work correctly, one must provide a property with name "archaius.deployment.applicationId" to archaius before karyon is initialized i.e. before calling initialize(). The value of the property must be the name of the application. By doing the above, archaius loads all properties defined in properties file(s) having the names: [application_name].properties [application_name]-[environement].properties The environment above is as retrieved from DeploymentContext.getApplicationId() from the deployment context configured in archaius. This can be set by a property "archaius.deployment.environment" NOTE: The above property names are valid if the default deployment context is used for archaius. If any customization is required in archaius, one should do the same before calling initialize().

Example

One can create a very simple server using karyon as:
 public class MyServer {

     public static void main(String[] args) throws Exception {
         final KaryonServer server = new KaryonServer();
         server.initialize();
         server.start();

         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

                public void run() {
                    try {
                        server.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }));

         ServerSocket serverSocket = new ServerSocket(80);
         while (true) {
         final Socket s = serverSocket.accept();
         // Process request
         }
     }
}
 


Field Summary
protected static org.slf4j.Logger logger
           
 
Constructor Summary
KaryonServer()
           
 
Method Summary
 void close()
          Stops the karyon server by stopping Governator and ServerInitializer.close().
 com.google.inject.Injector initialize()
          Bootstraps karyon by using ServerBootstrap by default.
 void start()
          Starts the karyon server by starting Governator and calling ServerInitializer.initialize(com.google.inject.Injector) for the applications, components to be started inside karyon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger
Constructor Detail

KaryonServer

public KaryonServer()
Method Detail

initialize

public com.google.inject.Injector initialize()
Bootstraps karyon by using ServerBootstrap by default. This can be customized by extending ServerBootstrap.
This method must be called during the server initialization.

Returns:
Guice's injector instance that will be used by Governator

start

public void start()
           throws java.lang.Exception
Starts the karyon server by starting Governator and calling ServerInitializer.initialize(com.google.inject.Injector) for the applications, components to be started inside karyon.
This typically should be called at startup.

Throws:
java.lang.Exception - If startup fails for any reason.

close

public void close()
           throws java.io.IOException
Stops the karyon server by stopping Governator and ServerInitializer.close().
This typically should be called at termination of the server.

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException