Example usage for org.springframework.context.support FileSystemXmlApplicationContext registerShutdownHook

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext registerShutdownHook

Introduction

In this page you can find the example usage for org.springframework.context.support FileSystemXmlApplicationContext registerShutdownHook.

Prototype

@Override
public void registerShutdownHook() 

Source Link

Document

Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.

Usage

From source file:net.phoenix.thrift.server.Server.java

/**
 * ? spring?//from   ww  w. j a va 2  s . c  o m
 * @param args
 * @throws Exception
 */
public static int main(String[] args) throws Exception {
    if (args.length == 0 || StringUtils.isEmpty(args[0])) {
        LOG.error("Please assign spring configuration file . ");
        return 0;
    }
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext();
    context.setConfigLocation(args[0]);
    context.registerShutdownHook();
    context.refresh();
    context.close();
    return 1;
}

From source file:com.paxxis.cornerstone.service.spring.CornerstoneService.java

/**
 * The main// w ww .ja v a 2  s  .c o m
 *
 * @param args the command line arguments.  There should be only
 * 1 command line argument -- the spring factory xml file.
 */
public static void main(String[] args) {
    // all we do is load the container
    FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[0]);
    ctx.registerShutdownHook();
}

From source file:com.intertech.tests.ServiceTest.java

/**
 * Test contact service./*from  ww w . ja v  a  2s .  c o  m*/
 */
public static void testContactService() {
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
            new String[] { "spring-beans.xml", "test-beans.xml" });
    context.registerShutdownHook();
    ContactList list = context.getBean("testList", ContactList.class);
    ContactService service = context.getBean("contactService", ContactService.class);
    List<Contact> contacts = list.getContacts();
    for (Contact contact : contacts) {
        service.addContact(contact);
        System.out.println("Test: " + contact + " was added to the Contact DB");
    }
    System.out.println("Test: Married contacts:  " + marriedContacts(contacts));
}

From source file:org.springframework.xd.gemfire.CacheServer.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Usage: CacheServer <config-file-path>");
        System.exit(1);//from   w  w w . j a v  a 2s  .  c  o  m
    }
    String path = args[0];

    if (!portAvailable(port)) {
        System.out.println("Cache Server port " + port + " is not available. Is another instance running?");
        System.exit(1);
    }
    logger.info("Starting Cache Server");
    @SuppressWarnings("resource")
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(path);
    context.registerShutdownHook();
    Cache cache = context.getBean(Cache.class);
    ManagementService ms = ManagementService.getExistingManagementService(cache);
    CacheServerMXBean cacheServerManager = ms.getLocalCacheServerMXBean(port);
    if (!cacheServerManager.isRunning()) {
        System.out.println("failed to start cache server ");
        System.exit(1);
    }
    System.out.println("cache server running");
}

From source file:org.springframework.xd.gemfire.server.CacheServer.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Usage: CacheServer <config-file-path>");
        System.exit(1);/*from   w  w  w .  ja  v  a2 s  .  co  m*/
    }

    /*
     * Ensure absolute path is handled
     */
    String path = args[0];
    if (!path.startsWith("file:")) {
        path = "file:" + path;
    }

    if (!portAvailable(port)) {
        System.out.println("Cache Server port " + port + " is not available. Is another instance running?");
        System.exit(1);
    }
    logger.info("Starting Cache Server");
    @SuppressWarnings("resource")
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(path);
    context.registerShutdownHook();
    Cache cache = context.getBean(Cache.class);
    ManagementService ms = ManagementService.getExistingManagementService(cache);
    CacheServerMXBean cacheServerManager = ms.getLocalCacheServerMXBean(port);
    if (!cacheServerManager.isRunning()) {
        System.out.println("failed to start cache server ");
        System.exit(1);
    }
    System.out.println("cache server running");
}