Package com.tailf.ncs

Class NcsMain

Object
com.tailf.ncs.NcsMain
All Implemented Interfaces:
Runnable, Thread.UncaughtExceptionHandler

public class NcsMain extends Object implements Runnable, Thread.UncaughtExceptionHandler
Main class for Ncs java vm management and control. This class implements the Runnable interface and should be started in a thread which becomes the Ncs java vm main thread. Normally this thread is instantiated and started by the NcsJVMLauncher which contains a main() method. It is however possible to embed and start the NcsMain thread from any other java program by inserting the following code snippet:
 NcsMain ncs = NcsMain.getInstance(host, port);
 Thread ncsThread = new Thread(ncs);
 ncsThread.start();
 
The Ncs java vm main thread will connect to the Ncs Server and start negotiation of which packages/components that should be instantiated registered and started. No manual registration is necessary.
  • Field Details

    • TAILF_CLASSLOADER

      public static final String TAILF_CLASSLOADER
      This field represents a system property controlling which classloader the Ncs java vm should use. If the system classloader is preferred this property should be set "false". The default is true If the system classloader is used, redeployment is not possible Example: java -cp ... -DTAILF_CLASSLOADER=false com...NcsJVMLauncher
      See Also:
  • Method Details

    • getNcsHost

      @Deprecated public String getNcsHost()
      Deprecated.
      Use the getAddress() method instead
      Get the hostname or IP address for the NCS Server.
      Returns:
      hostname or IP address for NCS server
    • getNcsPort

      @Deprecated public int getNcsPort()
      Deprecated.
      Use the getAddress() method instead
      Get the port number for the NCS Server.
      Returns:
      NCS server port
    • getAddress

      public SocketAddress getAddress()
      Get the address for the NCS Server.
      Returns:
      socket address for the NCS server
    • getSinkCentral

      public AlarmSinkCentral getSinkCentral()
      Get the NCS AlarmSinkCentral instance.
      Returns:
      AlarmSinkCentral instance
    • getSourceCentral

      public AlarmSourceCentral getSourceCentral()
      Get the NCS AlarmSourceCentral instance.
      Returns:
      AlarmSourceCentral instance
    • getDPMuxManager

      public com.tailf.ncs.ctrl.DpMuxManager getDPMuxManager()
      Get the DpMuxManager instance. This manager controls the DP instances and all registered callback components from all packages.
      Returns:
      DpMuxManager instance
    • getNedMuxManager

      public com.tailf.ncs.ctrl.NedMuxManager getNedMuxManager()
      Get the NedMuxManager instance. This manager controls the NedMux and all registered NED components from all packages.
      Returns:
      NedMuxManager instance
    • getApplicationMuxManager

      public com.tailf.ncs.ctrl.ApplicationMuxManager getApplicationMuxManager()
      Get the ApplicationMuxManager instance. This manager controls all application component threads from all packages.
      Returns:
      ApplicationMuxManager instance
    • getResourceManager

      public ResourceManager getResourceManager()
      Get the ResourceManager instance.
      Returns:
      resource manager for this NCS instance
    • run

      public void run()
      This method is the Ncs java vm main thread start
      Specified by:
      run in interface Runnable
    • isUsingTailFClassloader

      public boolean isUsingTailFClassloader()
      Checks if this instance was started with the Tail-f Jar classloader, as opposed to running with the standard java system classloader. The default is running with the Tail-f Jar classloader, which is necessary to be able to perform component hot re-deploy.
      Returns:
      true if the Tail-f Jar classloader is active
    • isAddingPkgs

      public boolean isAddingPkgs()
      Checks if packages are being added to the system.
      Returns:
      true if packages are currently being added
    • instantiatePackageComponent

      public void instantiatePackageComponent(com.tailf.ncs.ctrl.NcsPDData pdData) throws Exception
      Instantiates and registers components for an NCS package.
      Parameters:
      pdData - package deployment data containing components to instantiate
      Throws:
      Exception - if component instantiation fails
    • redeployPackage

      public void redeployPackage(com.tailf.ncs.ctrl.NcsPDData pdData) throws Exception
      Hot redeploy of all components for a package.
      Parameters:
      pdData - package deployment data for the package to redeploy
      Throws:
      Exception - if redeployment fails
    • isStarted

      @Deprecated public static boolean isStarted()
      Deprecated.
      Use isRunning() instead
      Checks if the NCS main thread has been started.
      Returns:
      true if the NCS main thread is running
    • isRunning

      public boolean isRunning()
      Checks if the NCS main thread is running.
      Returns:
      true if the NCS main thread is running
    • getInstance

      public static NcsMain getInstance()
      Gets the NcsMain instance associated with the current thread.
      Returns:
      instance associated with the current thread, or null if no instance has been started
    • getLocalInstance

      public static Optional<NcsMain> getLocalInstance()
      Gets the NcsMain instance associated with the current thread.
      Returns:
      an optional containing the instance associated with the current thread, or empty of no instance has been started
    • getInstance

      @Deprecated public static NcsMain getInstance(String host, int port)
      Deprecated.
      Gets the singleton instance of the NcsMain class.
      Parameters:
      host - the NCS host to connect to
      port - the NCS port to connect to
      Returns:
      NcsMain instance
    • getInstance

      public static NcsMain getInstance(SocketAddress address)
      Get an instance that should connect to the given address. If an instance already exists for the given address it is returned.
      Parameters:
      address - socket address to connect to
      Returns:
      an instance that is connected or will connect to the given address
    • abortNcsJavaVM

      @Deprecated public static void abortNcsJavaVM(Object obj)
      Deprecated.
      Use shutdown() instead.
      Aborts the NCS Java VM.
      Parameters:
      obj - the object context (unused)
    • abortNcsJavaVM

      @Deprecated public static void abortNcsJavaVM(Object obj, int code)
      Deprecated.
      Use shutdown() instead.
      Aborts the NCS Java VM with exit code.
      Parameters:
      obj - the object context (unused)
      code - the exit code (unused)
    • abortNcsJavaVM

      @Deprecated public static void abortNcsJavaVM(Object obj, int code, String message)
      Deprecated.
      Use shutdown() instead.
      Abort Ncs Java VM
      Parameters:
      obj - the object context (unused)
      code - the exit code (unused)
      message - the error message (unused)
    • reportPackageException

      @Deprecated public static Throwable reportPackageException(Object instance, Throwable e)
      Reports package exceptions and initiates restart handling.
      Parameters:
      instance - the component instance that threw the exception
      e - the exception to report
      Returns:
      the processed exception
    • reportPackageException

      @Deprecated public static Throwable reportPackageException(ClassLoader cl, Throwable e)
      Reports package exceptions using class loader context.
      Parameters:
      cl - the class loader of the failing package
      e - the exception to report
      Returns:
      the processed exception
    • reportPackageException

      @Deprecated public static Throwable reportPackageException(String packageName, Throwable e)
      Reports package exceptions by package name.
      Parameters:
      packageName - the name of the failing package
      e - the exception to report
      Returns:
      the processed exception
    • handlePackageException

      public Throwable handlePackageException(Object instance, Throwable e)
      Handles exceptions from package components.
      Parameters:
      instance - the object instance that threw the exception
      e - the exception to handle
      Returns:
      the exception to be thrown
    • handlePackageException

      public Throwable handlePackageException(ClassLoader cl, Throwable e)
      Handles exceptions from package components by class loader context.
      Parameters:
      cl - the class loader associated with the failing package
      e - the exception to handle
      Returns:
      the exception to be thrown
    • handlePackageException

      public Throwable handlePackageException(String packageName, Throwable e)
      Handles exceptions from a specific package by name.
      Parameters:
      packageName - the name of the package that generated the exception
      e - the exception to handle
      Returns:
      the exception to be thrown
    • submitPackageAlarm

      public static void submitPackageAlarm(Object instance, ConfIdentityRef alarmType, PerceivedSeverity severity, boolean cleared, String alarmText)
      Submits an alarm for a package component instance.
      Parameters:
      instance - the component instance generating the alarm
      alarmType - the type of alarm to submit
      severity - the perceived severity of the alarm
      cleared - whether the alarm is cleared
      alarmText - descriptive text for the alarm
    • submitPackageAlarm

      public static void submitPackageAlarm(ClassLoader cl, ConfIdentityRef alarmType, PerceivedSeverity severity, boolean cleared, String alarmText)
      Submits an alarm for a package using its class loader context.
      Parameters:
      cl - the class loader of the package generating the alarm
      alarmType - the type of alarm to submit
      severity - the perceived severity of the alarm
      cleared - whether the alarm is cleared
      alarmText - descriptive text for the alarm
    • submitPackageAlarm

      public static void submitPackageAlarm(String packageName, ConfIdentityRef alarmType, PerceivedSeverity severity, boolean cleared, String alarmText)
      Submits an alarm for a specific package by name.
      Parameters:
      packageName - the name of the package generating the alarm
      alarmType - the type of alarm to submit
      severity - the perceived severity of the alarm
      cleared - whether the alarm is cleared
      alarmText - descriptive text for the alarm
    • shutdown

      public void shutdown()
      shutdown Ncs java vm main thread
    • restartPackage

      public void restartPackage(String packageName)
      Schedules a package for restart.
      Parameters:
      packageName - the name of the package to restart
    • restartPackageNow

      public void restartPackageNow(String packageName)
      Immediately restarts a package
      Parameters:
      packageName - the name of the package to restart
    • uncaughtException

      public void uncaughtException(Thread t, Throwable e)
      Handles uncaught exceptions from any thread by initiating system shutdown.
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
      Parameters:
      t - the thread that threw the uncaught exception
      e - the uncaught exception