use of org.apache.openejb.server.ServiceException in project tomee by apache.
the class TomcatLoader method destroy.
/**
* Destroy system.
*/
public static void destroy() {
for (final ServerService s : services) {
try {
s.stop();
} catch (final ServiceException ignored) {
// no-op
}
}
// Stop ServiceManager
if (manager != null) {
try {
manager.stop();
} catch (final ServiceException e) {
// no-op
}
manager = null;
}
// Stop Ejb server
if (ejbServer != null) {
try {
ejbServer.stop();
} catch (final ServiceException e) {
// no-op
}
ejbServer = null;
}
final TomcatWebAppBuilder tomcatWebAppBuilder = (TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class);
if (tomcatWebAppBuilder != null) {
try {
tomcatWebAppBuilder.stop();
} catch (final Exception ignored) {
// no-op
}
}
// Destroy OpenEJB system
OpenEJB.destroy();
}
use of org.apache.openejb.server.ServiceException in project tomee by apache.
the class MulticastDiscoveryAgent method start.
/**
* start the discovery agent
*
* @throws ServiceException
*/
@Override
public void start() throws ServiceException {
try {
if (running.compareAndSet(false, true)) {
final InetAddress inetAddress = InetAddress.getByName(host);
this.address = new InetSocketAddress(inetAddress, port);
multicast = new Multicast(tracker);
}
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of org.apache.openejb.server.ServiceException in project tomee by apache.
the class MulticastPulseAgent method start.
@Override
public void start() throws ServiceException {
if (!this.running.getAndSet(true)) {
try {
this.sockets = getSockets(this.multicast, this.port);
} catch (final Exception e) {
throw new ServiceException("Failed to get Multicast sockets", e);
}
final CountDownLatch latch = new CountDownLatch(this.sockets.length);
final String mpg = this.group;
final boolean isLoopBackOnly = this.loopbackOnly;
final ExecutorService executorService = getExecutorService();
final MulticastPulseAgent agent = MulticastPulseAgent.this;
for (final MulticastSocket socket : this.sockets) {
final String socketKey;
try {
socketKey = socket.getNetworkInterface().toString();
} catch (final SocketException e) {
LOG.error("Failed to get network interface name on: " + socket, e);
continue;
}
final Sender sender = new Sender(this, socketKey, socket);
this.futures.add(executorService.submit(sender));
this.futures.add(executorService.submit(new Runnable() {
@Override
public void run() {
final DatagramPacket request = new DatagramPacket(new byte[2048], 2048);
latch.countDown();
while (agent.running.get()) {
try {
socket.receive(request);
final SocketAddress sa = request.getSocketAddress();
if (null != sa) {
String req = new String(request.getData(), 0, request.getLength());
if (req.startsWith(CLIENT)) {
final int ix = req.indexOf(BADURI);
String badUri = null;
if (ix > 0) {
// The client is notifying of a bad uri
badUri = req.substring(ix).replace(BADURI, "");
req = req.substring(0, ix).replace(CLIENT, "");
} else {
req = (req.replace(CLIENT, ""));
}
// Is this a group or global pulse request
if (mpg.equals(req) || "*".equals(req)) {
// Is there a bad url and is it this agent broadcasting the bad URI?
if (null != badUri) {
if (getHosts(agent.ignore).contains(badUri)) {
final ReentrantLock l = agent.lock;
l.lock();
try {
// Remove it and rebuild our broadcast packet
if (agent.ignore.add(badUri)) {
agent.buildPacket();
LOG.warning("This server has removed the unreachable host '" + badUri + "' from discovery, you should consider adding" + " this to the 'ignore' property in the multipulse.properties file");
}
} finally {
l.unlock();
}
}
agent.fireEvent(URI.create("OpenEJB" + BADURI + badUri), false);
} else {
// Normal client multicast pulse request
final String client = ((InetSocketAddress) sa).getAddress().getHostAddress();
if (isLoopBackOnly && !MulticastPulseAgent.isLocalAddress(client, false)) {
// We only have local services, so make sure the request is from a local source else ignore it
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Ignoring remote client %1$s pulse request for group: %2$s - No remote services available", client, req));
}
} else {
// We have received a valid pulse request
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Answering client '%1$s' pulse request for group: '%2$s' on '%3$s'", client, req, socketKey));
}
// Renew response pulse
sender.pulseResponse();
}
}
}
}
}
} catch (final Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug("MulticastPulseAgent request error: " + e.getMessage(), e);
}
}
}
try {
socket.close();
} catch (final Throwable e) {
// Ignore
}
}
}));
}
try {
// Give threads a reasonable amount of time to start
latch.await(5, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
this.stop();
}
}
}
use of org.apache.openejb.server.ServiceException in project tomee by apache.
the class HsqlService method init.
@Override
public void init(final Properties p) throws Exception {
final Properties properties = new Properties();
for (final Map.Entry<Object, Object> entry : p.entrySet()) {
// Sometimes the properties object has non string values
if (!(entry.getKey() instanceof String))
continue;
if (!(entry.getValue() instanceof String))
continue;
final String property = (String) entry.getKey();
final String value = (String) entry.getValue();
if (property.startsWith(sc_key_dbname + ".") || property.startsWith(sc_key_database + ".")) {
throw new ServiceException("Databases cannot be declared in the hsql.properties. " + "Instead declare a database connection in the openejb.conf file");
}
if ("port".equals(property)) {
properties.setProperty(sc_key_port, value);
} else if ("bind".equals(property)) {
properties.setProperty(sc_key_address, value);
} else {
properties.setProperty(property, value);
}
}
properties.setProperty(sc_key_no_system_exit, "true");
final boolean disabled = Boolean.parseBoolean(properties.getProperty("disabled"));
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
if (!disabled && containerSystem != null) {
final NamingEnumeration<Binding> bindings;
try {
bindings = containerSystem.getJNDIContext().listBindings("openejb/Resource/");
final Set<String> dbnames = new TreeSet<String>();
for (final Binding binding : Collections.list(bindings)) {
final Object value = binding.getObject();
if (value instanceof DataSource) {
final DataSource jdbc = (DataSource) value;
Connection connection = null;
String path = null;
try {
connection = jdbc.getConnection();
final DatabaseMetaData meta = connection.getMetaData();
path = getPath(meta.getDriverName(), meta.getURL());
} catch (Throwable t) {
continue;
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException sqlEx) {
// no-op
}
}
}
if (path != null) {
if (dbnames.size() > 9) {
throw new ServiceException("Hsql Server can only host 10 database instances");
}
String dbname = path.substring(path.lastIndexOf(':') + 1);
dbname = dbname.substring(dbname.lastIndexOf('/') + 1);
if (!dbnames.contains(dbname)) {
properties.put(sc_key_dbname + "." + dbnames.size(), dbname);
properties.put(sc_key_database + "." + dbnames.size(), path);
dbnames.add(dbname);
}
}
}
}
} catch (NameNotFoundException e) {
// Ignore
}
// create the server
server = new Server();
// add the silent property
properties.setProperty(sc_key_silent, "true");
// set the log and error writers
server.setLogWriter(new HsqlPrintWriter(false));
server.setErrWriter(new HsqlPrintWriter(true));
server.setProperties(new HsqlProperties(properties));
// get the port
port = server.getPort();
// get the Address
final String ipString = server.getAddress();
if (ipString != null && ipString.length() > 0) {
this.ip = ipString;
}
}
}
use of org.apache.openejb.server.ServiceException in project tomee by apache.
the class MultipointDiscoveryAgent method start.
/**
* start the discovery agent
*
* @throws ServiceException On error
*/
@Override
@Managed
public void start() throws ServiceException {
try {
if (running.compareAndSet(false, true)) {
LOGGER.info("MultipointDiscoveryAgent Starting");
multipointServer = new MultipointServer(host, discoveryHost, port, tracker, name, debug, roots, reconnectDelay).start();
LOGGER.info("MultipointDiscoveryAgent Started");
this.port = multipointServer.getPort();
}
} catch (Exception e) {
throw new ServiceException(port + "", e);
}
}
Aggregations