Example usage for org.apache.commons.lang3 StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(final String str, final String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans,
        Map<String, String> dictionary) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary);
    nameCutter.setDictionary(dictionary);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);/*from w w  w.  j  a  v a  2 s .co  m*/
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        String[] domains = mBeanServerConnection.getDomains();
        logger.info("Found " + domains.length + " domains");
        logger.info("domains: " + Arrays.toString(domains));
        for (String domainName : domains) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.info("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable
                            // mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }
    logger.debug("finish collection!");
    return xmlJmxDatacollectionConfig;
}

From source file:org.opennms.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans,
        Map<String, String> dictionary) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary);
    nameCutter.setDictionary(dictionary);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);// w  ww . j a  va 2  s .c  o  m
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        for (String domainName : mBeanServerConnection.getDomains()) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.debug("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }

    return xmlJmxDatacollectionConfig;
}

From source file:org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);//from  w  w  w .j av a 2  s. c  o m
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        for (String domainName : mBeanServerConnection.getDomains()) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.debug("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }

    return xmlJmxDatacollectionConfig;
}

From source file:org.pad.pgsql.loadmovies.LoadFiles.java

/**
 * Load movies from csv file and save them in DB.
 *
 * @throws Exception/*from www .j  av  a 2s .c  o m*/
 */
private static void loadMoviesAndLinks() throws Exception {
    MovieDao movieDao = new MovieDao(DS);
    Map<Integer, Integer[]> moviesLinks = new HashMap<>();
    //Loads all links informations in memory to enrich afterwards movies
    CSVParser parser = new CSVParser(new FileReader("C:\\PRIVE\\SRC\\ml-20m\\links.csv"),
            CSVFormat.EXCEL.withHeader());
    for (CSVRecord link : parser) {
        Integer movieId = Integer.parseInt(link.get("movieId"));
        if (keepId(movieId)) {
            System.out.println("Parsing line " + link.toString());
            Integer[] otherIds = new Integer[2];
            otherIds[0] = Integer.parseInt(link.get("imdbId"));
            if (StringUtils.isNoneEmpty(link.get("tmdbId"))) {
                otherIds[1] = Integer.parseInt(link.get("tmdbId"));
            }
            moviesLinks.put(movieId, otherIds);
        }
    }

    //Read movie file
    final Reader reader = new FileReader("C:\\PRIVE\\SRC\\ml-20m\\movies.csv");
    parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());

    for (CSVRecord record : parser) {
        //build a movie object from record
        Integer movieId = Integer.parseInt(record.get("movieId"));
        if (keepId(movieId)) {
            String title = record.get("title");
            String genres = record.get("genres");
            //Splitting title to extract the date
            String movieDate = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(title, "("), ")");
            String movieName = null;
            if (StringUtils.isNumeric(movieDate)) {
                movieName = StringUtils.substringBeforeLast(title, "(");
            } else {
                movieName = title;
                movieDate = null;
            }

            System.out.println(movieName + " - " + movieDate);
            Movie movieToAdd = new Movie(movieId, movieName, movieDate);

            //Enrich movie with links
            Integer[] additionalIds = moviesLinks.get(movieId);
            if (additionalIds != null) {
                movieToAdd.setImdbId(additionalIds[0]);
                movieToAdd.setTmdbId(additionalIds[1]);
            }

            //Save in database
            movieDao.save(movieToAdd);
        }
    }
}

From source file:org.paxml.core.PaxmlResource.java

/**
 * Create resource from full path./*from ww  w.  ja va 2 s. c  o m*/
 * 
 * @param pathWithPrefix
 *            the full path with prefix. See all subclasses of this class
 *            for the possible prefixes.
 * @return the resource or null if the prefix is not supported.
 */
public static PaxmlResource createFromPath(String pathWithPrefix) {
    if (pathWithPrefix.startsWith(FileSystemResource.PREFIX)) {
        return new FileSystemResource(new File(pathWithPrefix.substring(FileSystemResource.PREFIX.length())));
    } else if (pathWithPrefix.startsWith(ClasspathResource.SPRING_PREFIX1)) {
        String barePath = pathWithPrefix.substring(ClasspathResource.SPRING_PREFIX1.length());

        return new ClasspathResource(barePath);
    } else if (pathWithPrefix.startsWith(ClasspathResource.SPRING_PREFIX2)) {
        String barePath = pathWithPrefix.substring(ClasspathResource.SPRING_PREFIX2.length());

        return new ClasspathResource(barePath);
    } else if (pathWithPrefix.startsWith("jar:")) {
        String barePath = StringUtils.substringAfterLast(pathWithPrefix, "!");
        return new ClasspathResource(barePath);
    }
    return null;

}

From source file:org.paxml.core.ResourceLocator.java

/**
 * Find all resources with a spring path pattern, from the added resources.
 * //w  w  w.  j  ava2 s. c o  m
 * @param springPattern
 *            the spring path pattern.
 * @param baseFile
 *            the file used to resolve relative path with, can be null if
 *            the pattern is not relative.
 * @return all resource found, never null.
 */
public static Set<PaxmlResource> findResources(String springPattern, Resource baseFile) {

    springPattern = springPattern.trim();

    if (StringUtils.isBlank(springPattern)) {
        throw new PaxmlRuntimeException("Cannot have empty file pattern!");
    }

    Set<PaxmlResource> set = new LinkedHashSet<PaxmlResource>();
    if (!springPattern.startsWith("file:") && !springPattern.startsWith("classpath:")
            && !springPattern.startsWith("classpath*:")) {
        springPattern = getRelativeResource(baseFile, springPattern);
    }
    if (log.isInfoEnabled()) {
        log.info("Searching paxml resource with pattern: " + springPattern);
    }
    try {
        for (Resource res : new PathMatchingResourcePatternResolver().getResources(springPattern)) {

            if (res instanceof ClassPathResource) {
                set.add(new ClasspathResource((ClassPathResource) res));
            } else if (res instanceof UrlResource && res.getURI().toString().startsWith("jar:")) {

                set.add(new ClasspathResource(
                        new ClassPathResource(StringUtils.substringAfterLast(res.getURI().toString(), "!"))));

            } else {
                try {
                    File file = res.getFile();
                    if (file.isFile()) {
                        set.add(new FileSystemResource(file));
                    }
                } catch (IOException e) {
                    throw new PaxmlRuntimeException("Unsupported spring resource: " + res.getURI()
                            + ", of type: " + res.getClass().getName());
                }
            }
        }
    } catch (IOException e) {
        throw new PaxmlRuntimeException("Cannot find resources with spring pattern: " + springPattern, e);
    }
    return set;
}

From source file:org.paxml.tag.sql.DdlScript.java

public DdlScript(File container, String file) {
    this.file = file;
    file = FilenameUtils.getBaseName(file);
    String v = StringUtils.substringAfterLast(file, "-");
    this.version = new DdlVersion(v);
    this.container = container;
    this.type = Type.parse(file);
}

From source file:org.pepstock.jem.node.JclCheckingQueueManager.java

/**
 * Access to queue and stay in wait for Prejob to check and validate.
 * /*from  ww  w  . ja  v  a 2 s  . c o  m*/
 * @see org.pepstock.jem.node.Queues#JCL_CHECKING_QUEUE
 */
public void run() {
    // gets HC queue
    IQueue<PreJob> jclCheckingQueue = Main.getHazelcast().getQueue(Queues.JCL_CHECKING_QUEUE);
    try {
        // reads from queue (waiting if necessary) and checks.. forever
        // if shutdown is not in progress
        while (!Main.IS_SHUTTING_DOWN.get()) {
            // checks if the node is really working and not in access MAINT
            if (Main.getNode().isOperational() && !Main.IS_ACCESS_MAINT.get()) {

                // creates a transaction to rollback if there is any exception
                // done because it removes from queue and adds the job on input map
                // and an exception must rollback everything, re-putting the job in queue for check
                Transaction tran = Main.getHazelcast().getTransaction();
                tran.begin();
                // gets the job
                PreJob prejob = poll(jclCheckingQueue);

                // checks because when the system is shutting
                // down, hazecast gets a null object
                if (prejob != null) {
                    // check JCL
                    checkAndLoadJcl(prejob);
                    // commit always! Rollback is never necessary
                    // Rollback is called automatically when node crashed
                    tran.commit();
                } else {
                    // commit always! Rollback is never necessary
                    // Rollback is called automatically when node crashed
                    tran.commit();
                    Thread.sleep(2 * TimeUtils.SECOND);
                }
            } else {
                // sleeps 15 second before checks if there is a new job on queue
                Thread.sleep(15 * TimeUtils.SECOND);
            }
        }
    } catch (InterruptedException e) {
        LogAppl.getInstance().emit(NodeMessage.JEMC068W,
                StringUtils.substringAfterLast(JclCheckingQueueManager.class.getName(), "."));
    }
    LogAppl.getInstance().emit(NodeMessage.JEMC069I,
            StringUtils.substringAfterLast(JclCheckingQueueManager.class.getName(), "."));
    // if here, the node is down
    isDown = true;
}

From source file:org.pepstock.jem.node.ShutDownHandler.java

/**
 * Main method, called by JVM to clean up.<br>
 * In sequence :<br>/*  w  w  w . j  av  a  2  s.  c  o m*/
 * <br>
 * <ul>
 * <ol>
 * sets a static reference <code>Main.IS_SHUTTINGDOWN</code> to
 * <code>true</code>
 * </ol>
 * <ol>
 * drains the initiator
 * </ol>
 * <ol>
 * waits for initiator in DRAINED (if there is a job in execution, it waits)
 * </ol>
 * <ol>
 * interrupts all threads passed by arguments in the constructor
 * </ol>
 * <ol>
 * shuts down Hazelcast, removing itself from Hazelcast group
 * </ol>
 * <ol>
 * Closes all databases connection (for Job, Roles, CommonResources)
 * </ol>
 * </ul>
 */

public void run() {
    ILock shutdownSynch = null;

    if (Main.getNode() != null) {
        // writes to log that is shutting down
        LogAppl.getInstance().emit(NodeMessage.JEMC071I, Main.getNode().getLabel());

        if (Main.getHazelcast() != null) {
            shutdownSynch = Main.getHazelcast().getLock(Queues.SHUTDOWN_LOCK);
            shutdownSynch.lock();
        }
        // sets the static reference to true
        Main.IS_SHUTTING_DOWN.set(true);

        // drains initiator
        NodeInfoUtility.drain();
        // waits for a second before to check the status
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // ignore
        }
        // waits for the status is drained (means the end of eventually
        // execution job)
        while (!Main.getNode().getStatus().equals(Status.DRAINED)) {
            if (!Main.CURRENT_TASKS.isEmpty()) {
                for (CancelableTask task : Main.CURRENT_TASKS.values()) {
                    LogAppl.getInstance().emit(NodeMessage.JEMC072I, task.getJobTask().getJob().toString());
                }
            }
            try {
                Thread.sleep(10 * TimeUtils.SECOND);
            } catch (InterruptedException e) {
                // ignore
            }
        }
    }

    // interrupts all threads
    if (Main.JCL_CHECKER != null) {
        try {
            Main.JCL_CHECKER.shutdown();
        } catch (Exception e) {
            LogAppl.getInstance().emit(NodeMessage.JEMC162E, e,
                    StringUtils.substringAfterLast(JclCheckingQueueManager.class.getName(), "."));
        }
    }

    // interrupts all threads
    if (Main.INPUT_QUEUE_MANAGER != null) {
        try {
            Main.INPUT_QUEUE_MANAGER.shutdown();
        } catch (Exception e) {
            LogAppl.getInstance().emit(NodeMessage.JEMC162E, e,
                    StringUtils.substringAfterLast(InputQueueManager.class.getName(), "."));
        }
    }

    // stops the statistics timer
    if (Main.getStatisticsManager() != null) {
        Main.getStatisticsManager().stop();
    }

    // interrupt Multicast Service
    if (Main.getMulticastService() != null) {
        Main.getMulticastService().shutdown();
    }

    if (Main.getHazelcast() != null) {
        // shuts down Hazelcast
        Main.getHazelcast().getLifecycleService().shutdown();
    }

    if (DBPoolManager.getInstance().isInitialized()) {
        // closes DB connection
        try {
            DBPoolManager.getInstance().close();
            LogAppl.getInstance().emit(NodeMessage.JEMC069I,
                    StringUtils.substringAfterLast(DBPoolManager.class.getName(), "."));
        } catch (Exception e) {
            LogAppl.getInstance().emit(NodeMessage.JEMC070E, e,
                    StringUtils.substringAfterLast(DBPoolManager.class.getName(), "."));
        }
    }
}

From source file:org.phenotips.configuration.internal.global.DefaultRecordElement.java

@Override
public String getName() {
    String result = this.extension.getParameters().get("title");
    if (StringUtils.isBlank(result)) {
        result = StringUtils.capitalize(StringUtils
                .replaceChars(StringUtils.substringAfterLast(this.extension.getId(), "."), "_-", "  "));
    }//  w w w  . jav  a2 s  . co m
    return result;
}