Search in sources :

Example 1 with FileTxLogImpl

use of com.sun.messaging.bridge.service.jms.tx.log.FileTxLogImpl in project openmq by eclipse-ee4j.

the class JMSBridge method exportJMSBridgeStoreService.

public static Object exportJMSBridgeStoreService(Properties props) throws Exception {
    String bname = props.getProperty("jmsbridge");
    String instanceRootDir = props.getProperty("instanceRootDir");
    String reset = props.getProperty("reset", "true");
    String logdomain = props.getProperty("logdomain");
    if (instanceRootDir == null) {
        throw new IllegalArgumentException("instanceRootDir not found in " + props);
    }
    if (logdomain == null) {
        throw new IllegalArgumentException("logdomain property not found in " + props);
    }
    String rootDir = instanceRootDir + File.separator + "bridges";
    props.setProperty("txlogDirParent", rootDir);
    boolean doreset = Boolean.parseBoolean(reset);
    File dir = new File(rootDir);
    if (doreset && bname == null) {
        if (dir.exists()) {
            if (!dir.renameTo(new File(rootDir + ".save"))) {
                throw new IOException("Unable to rename existing directory " + rootDir + " to " + rootDir + ".save");
            }
        }
        return null;
    }
    if (bname == null) {
        if (!dir.exists()) {
            return null;
        }
        File[] files = dir.listFiles();
        if (files == null) {
            throw new IOException("Can't list files in " + rootDir);
        }
        if (files.length == 0) {
            return null;
        }
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                bname = files[i].getName();
                break;
            }
        }
        if (bname == null) {
            return null;
        }
        props.setProperty("jmsbridge", bname);
    }
    if (!dir.exists()) {
        dir.mkdirs();
    }
    Logger logger = Logger.getLogger(logdomain);
    props.setProperty("txlogDir", rootDir);
    props.setProperty("tmname", props.getProperty("identityName") + ":" + bname);
    props.setProperty("txlogSuffix", bname);
    String txlogDir = rootDir + File.separator + bname;
    props.setProperty("txlogDir", txlogDir);
    dir = new File(txlogDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    String logfile = dir + File.separator + "jms%g.log";
    FileHandler h = new FileHandler(logfile, true);
    h.setFormatter(new LogSimpleFormatter(logger));
    logger.addHandler(h);
    logger.log(Level.INFO, "Exported JMSBridgeStore txlogDir is " + txlogDir);
    logger.log(Level.INFO, "Exported JMSBridgeStore uses log domain: " + logdomain);
    logger.log(Level.INFO, "Exported JMSBridgeStore uses log file: " + logfile);
    FileTxLogImpl txlog = new FileTxLogImpl();
    txlog.setLogger(logger);
    txlog.init(props, doreset);
    return txlog;
}
Also used : LogSimpleFormatter(com.sun.messaging.bridge.api.LogSimpleFormatter) IOException(java.io.IOException) Logger(java.util.logging.Logger) FileTxLogImpl(com.sun.messaging.bridge.service.jms.tx.log.FileTxLogImpl) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Aggregations

LogSimpleFormatter (com.sun.messaging.bridge.api.LogSimpleFormatter)1 FileTxLogImpl (com.sun.messaging.bridge.service.jms.tx.log.FileTxLogImpl)1 File (java.io.File)1 IOException (java.io.IOException)1 FileHandler (java.util.logging.FileHandler)1 Logger (java.util.logging.Logger)1