Search in sources :

Example 1 with LockFile

use of com.sun.messaging.jmq.jmsserver.util.LockFile in project openmq by eclipse-ee4j.

the class CommGlobals method getAuditSession.

/**
 * Get audit session
 */
public static MQAuditSession getAuditSession() {
    if (audit == null) {
        synchronized (lock) {
            if (audit == null) {
                MQAuditService.init();
                try {
                    audit = MQAuditService.getAuditSession();
                    LockFile lf = LockFile.getCurrentLockFile();
                    if (lf != null) {
                        audit.setInstance(lf.getInstance(), lf.getHost(), lf.getPort());
                    }
                } catch (BrokerException ex) {
                    getLogger().logStack(Logger.ERROR, ex.toString(), ex);
                    getCommBroker().exit(BrokerExitCode.ERROR, ex.toString(), BrokerEvent.Type.EXCEPTION);
                }
            }
        }
    }
    return audit;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) LockFile(com.sun.messaging.jmq.jmsserver.util.LockFile)

Example 2 with LockFile

use of com.sun.messaging.jmq.jmsserver.util.LockFile in project openmq by eclipse-ee4j.

the class PortMapper method setPort.

/**
 * Change the portmapper service's port
 */
private synchronized void setPort(int port) {
    if (port == this.port) {
        return;
    }
    this.port = port;
    addService(SERVICE_NAME, "tcp", "PORTMAPPER", port, portmapperMap);
    LockFile lf = LockFile.getCurrentLockFile();
    try {
        if (lf != null) {
            lf.updatePort(port, Globals.getUseFileLockForLockFile());
        }
    } catch (IOException e) {
        logger.log(Logger.WARNING, rb.E_LOCKFILE_BADUPDATE, e);
    }
    if (serverSocket != null) {
        // one with the new port
        try {
            serverSocket.close();
        } catch (IOException e) {
        }
    }
    PUService pu = Globals.getPUService();
    if (pu != null) {
        try {
            pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
        } catch (IOException e) {
            logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
        }
    }
}
Also used : PUService(com.sun.messaging.portunif.PUService) LockFile(com.sun.messaging.jmq.jmsserver.util.LockFile)

Example 3 with LockFile

use of com.sun.messaging.jmq.jmsserver.util.LockFile in project openmq by eclipse-ee4j.

the class PortMapper method setHostname.

/**
 * Change the portmapper service's host interface
 */
private synchronized void setHostname(String hostname, boolean initOnly) throws PropertyUpdateException {
    MQAddress mqaddr = null;
    try {
        String h = hostname;
        if (hostname != null && hostname.equals(Globals.HOSTNAME_ALL)) {
            h = null;
        }
        mqaddr = MQAddress.getMQAddress(h, getPort());
    } catch (Exception e) {
        throw new PropertyUpdateException(hostname + ": " + e.toString(), e);
    }
    if (hostname == null || hostname.equals(Globals.HOSTNAME_ALL) || hostname.trim().length() == 0) {
        // Bind to all
        this.hostname = null;
        this.bindAddr = null;
        mqaddress = mqaddr;
        if (!initOnly) {
            PUService pu = Globals.getPUService();
            if (pu != null) {
                try {
                    pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
                } catch (IOException e) {
                    logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
                }
            }
        }
        return;
    }
    if (hostname.equals(this.hostname)) {
        return;
    }
    try {
        if (Globals.isConfigForCluster()) {
            String hn = hostname;
            if (hn.equals("localhost")) {
                hn = null;
            }
            this.bindAddr = BrokerMQAddress.resolveBindAddress(hn, true);
            mqaddr = MQAddress.getMQAddress(this.bindAddr.getHostAddress(), getPort());
        } else {
            this.bindAddr = InetAddress.getByName(hostname);
        }
    } catch (Exception e) {
        throw new PropertyUpdateException(rb.getString(rb.E_BAD_HOSTNAME, hostname), e);
    }
    this.hostname = hostname;
    this.mqaddress = mqaddr;
    LockFile lf = LockFile.getCurrentLockFile();
    try {
        if (lf != null) {
            lf.updateHostname(mqaddress.getHostName(), Globals.getUseFileLockForLockFile());
        }
    } catch (IOException e) {
        logger.log(Logger.WARNING, rb.E_LOCKFILE_BADUPDATE, e);
    }
    if (serverSocket != null) {
        // one with the new port
        try {
            serverSocket.close();
        } catch (IOException e) {
        }
    }
    if (!initOnly) {
        PUService pu = Globals.getPUService();
        if (pu != null) {
            try {
                pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
            } catch (IOException e) {
                logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
            }
        }
    }
}
Also used : PUService(com.sun.messaging.portunif.PUService) MQAddress(com.sun.messaging.jmq.io.MQAddress) BrokerMQAddress(com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress) LockFile(com.sun.messaging.jmq.jmsserver.util.LockFile) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

LockFile (com.sun.messaging.jmq.jmsserver.util.LockFile)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 PUService (com.sun.messaging.portunif.PUService)2 MQAddress (com.sun.messaging.jmq.io.MQAddress)1 BrokerMQAddress (com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)1