Commit a2961e78 authored by Loïc Albertin's avatar Loïc Albertin
Browse files

#1032: Refactor JOnAS Services APIs

  * Make EasyBeans optional
parent 05c05f35
......@@ -71,6 +71,9 @@ import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
import org.apache.felix.ipojo.handlers.event.publisher.Publisher;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.ow2.jonas.Version;
import org.ow2.jonas.configuration.ConfigurationManager;
......@@ -233,7 +236,7 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
/**
* EasyBeans service instance.
*/
private IEasyBeansService easyBeansService;
private ServiceReference<?> easyBeansServiceReference;
/**
* Standby system property name.
......@@ -297,10 +300,13 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
*/
private File cacheDir;
private BundleContext bundleContext;
/**
* MBean constructor.
*/
public J2EEServer() {
public J2EEServer(BundleContext bundleContext) {
this.bundleContext = bundleContext;
setStateManageable(true);
setStatisticsProvider(false);
setEventProvider(true);
......@@ -1092,33 +1098,33 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
fileURL = new URL(fileName);
} catch (MalformedURLException e) {
throw new RuntimeException("The given filename '" + fileName + "' is neither an absolute file nor a valid URL.");
}
}
if (!urlsToFilesCache.containsKey(fileName)) {
if ("file".equalsIgnoreCase(fileURL.getProtocol())) {
f = URLUtils.urlToFile(fileURL);
} else {
// Let's download it locally.
try {
String finalFileName = fileURL.getPath();
if (finalFileName.endsWith("/")) {
finalFileName = fileName.substring(0, fileName.length() - 1);
}
if (finalFileName.contains("/")) {
finalFileName = finalFileName.substring(finalFileName.lastIndexOf("/") + 1);
if ("file".equalsIgnoreCase(fileURL.getProtocol())) {
f = URLUtils.urlToFile(fileURL);
} else {
// Let's download it locally.
try {
String finalFileName = fileURL.getPath();
if (finalFileName.endsWith("/")) {
finalFileName = fileName.substring(0, fileName.length() - 1);
}
if (finalFileName.contains("/")) {
finalFileName = finalFileName.substring(finalFileName.lastIndexOf("/") + 1);
}
File tmpFile = new File(cacheDir, finalFileName);
FileUtils.dump(fileURL.openStream(), tmpFile);
f = tmpFile;
} catch (IOException e) {
throw new RuntimeException("Unable to download '" + fileName + "' locally.");
} catch (FileUtilsException e) {
throw new RuntimeException("Unable to download '" + fileName + "' locally.");
}
File tmpFile = new File(cacheDir, finalFileName);
FileUtils.dump(fileURL.openStream(), tmpFile);
f = tmpFile;
} catch (IOException e) {
throw new RuntimeException("Unable to download '" + fileName + "' locally.");
} catch (FileUtilsException e) {
throw new RuntimeException("Unable to download '" + fileName + "' locally.");
}
}
urlsToFilesCache.put(fileName, f.getAbsolutePath());
urlsToFilesCache.put(fileName, f.getAbsolutePath());
} else {
f = new File(urlsToFilesCache.get(fileName));
}
}
}
final IDeployable deployable = getDeployable(f.getAbsolutePath());
......@@ -1272,10 +1278,6 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
this.registryService = registryService;
}
public void setEasyBeansService(final IEasyBeansService easyBeansService) {
this.easyBeansService = easyBeansService;
}
// --------------- JonasAdmin support -----------------------//
/**
* file extension containing a deployment plan
......@@ -2031,8 +2033,12 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
*/
private void registerEasyBeansEmbeddedService() {
// Register the Easybeans Embedded as an OSGi service
if (easyBeansService != null) {
easyBeansService.registerEmbeddedService();
ServiceReference<?> serviceReference = bundleContext.getServiceReference("org.ow2.jonas.ejb3.IEasyBeansService");
if (serviceReference != null) {
IEasyBeansService easyBeansService = (IEasyBeansService) bundleContext.getService(serviceReference);
if (easyBeansService != null) {
easyBeansService.registerEmbeddedService();
}
}
}
......
# ---------------------------------------------------------------------------
# JOnAS: Java(TM) Open Application Server
# Copyright (C) 2007-2012 Bull S.A.S.
# Copyright (C) 2007-2013 Bull S.A.S.
# Contact: jonas-team@ow2.org
#
# This library is free software; you can redistribute it and/or
......@@ -23,7 +23,9 @@
Private-Package org.ow2.jonas.lib.jmbeans.*
# org.ow2.jonas.ejb3 is optional break hard references to it
DynamicImport-Package javax.naming, \
org.ow2.jonas.ejb3, \
org.ow2.easybeans.api, \
org.ow2.easybeans.api.naming, \
org.ow2.easybeans.persistence.api, \
......
......@@ -31,9 +31,9 @@
<component classname="org.ow2.jonas.lib.jmbeans.MBeansRegistration"
name="MBeansRegistration"
public="false"
public="true"
immediate="true">
<provides/>
<requires optional="false">
<callback type="bind" method="setJmxService" />
</requires>
......@@ -57,7 +57,7 @@
<component classname="org.ow2.jonas.lib.jmbeans.J2EEServer"
name="J2EEServer"
public="false"
public="true"
immediate="true">
<provides specifications="org.ow2.jonas.management.J2EEServerService" />
......@@ -88,9 +88,6 @@
<callback type="bind" method="bindVersioningService" />
<callback type="unbind" method="unbindVersioningService" />
</requires>
<requires optional="true">
<callback type="bind" method="setEasyBeansService" />
</requires>
<requires optional="true"
specification="org.ow2.jonas.event.provider.api.IEventProvider">
<callback type="bind" method="bindEventProvider"/>
......@@ -106,4 +103,4 @@
<instance component="J2EEServer" />
<instance component="MBeansRegistration" />
</ipojo>
\ No newline at end of file
</ipojo>
......@@ -72,6 +72,9 @@ import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
import org.apache.felix.ipojo.handlers.event.publisher.Publisher;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.ow2.jonas.Version;
import org.ow2.jonas.configuration.ConfigurationManager;
......@@ -231,11 +234,6 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
*/
private RegistryService registryService = null;
/**
* EasyBeans service instance.
*/
private IEasyBeansService easyBeansService;
/**
* Standby system property name.
*/
......@@ -296,10 +294,13 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
*/
private File cacheDir;
private BundleContext bundleContext;
/**
* MBean constructor.
*/
public J2EEServer() {
public J2EEServer(BundleContext bundleContext) {
this.bundleContext = bundleContext;
setStateManageable(true);
setStatisticsProvider(false);
setEventProvider(true);
......@@ -1278,10 +1279,6 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
this.registryService = registryService;
}
public void setEasyBeansService(final IEasyBeansService easyBeansService) {
this.easyBeansService = easyBeansService;
}
// --------------- JonasAdmin support -----------------------//
/**
* file extension containing a deployment plan
......@@ -2041,8 +2038,12 @@ public class J2EEServer extends J2EEManagedObject implements J2EEServerService,
*/
private void registerEasyBeansEmbeddedService() {
// Register the Easybeans Embedded as an OSGi service
if (easyBeansService != null) {
easyBeansService.registerEmbeddedService();
ServiceReference<?> serviceReference = bundleContext.getServiceReference("org.ow2.jonas.ejb3.IEasyBeansService");
if (serviceReference != null) {
IEasyBeansService easyBeansService = (IEasyBeansService) bundleContext.getService(serviceReference);
if (easyBeansService != null) {
easyBeansService.registerEmbeddedService();
}
}
}
......
# ---------------------------------------------------------------------------
# JOnAS: Java(TM) Open Application Server
# Copyright (C) 2007-2009 Bull S.A.S.
# Copyright (C) 2007-2013 Bull S.A.S.
# Contact: jonas-team@ow2.org
#
# This library is free software; you can redistribute it and/or
......@@ -23,7 +23,9 @@
Private-Package org.ow2.jonas.lib.jmbeans.*
# org.ow2.jonas.ejb3 is optional break hard references to it
DynamicImport-Package javax.naming, \
org.ow2.jonas.ejb3, \
org.ow2.easybeans.api, \
org.ow2.easybeans.api.naming, \
org.ow2.easybeans.persistence.api, \
......
......@@ -31,7 +31,7 @@
<component classname="org.ow2.jonas.lib.jmbeans.MBeansRegistration"
name="MBeansRegistration"
public="true"
public="true"
immediate="true">
<provides/>
<requires optional="false">
......@@ -57,7 +57,7 @@
<component classname="org.ow2.jonas.lib.jmbeans.J2EEServer"
name="J2EEServer"
public="true"
public="true"
immediate="false">
<provides specifications="org.ow2.jonas.management.J2EEServerService" />
......@@ -88,9 +88,6 @@
<callback type="bind" method="bindVersioningService" />
<callback type="unbind" method="unbindVersioningService" />
</requires>
<requires optional="true">
<callback type="bind" method="setEasyBeansService" />
</requires>
<requires optional="true"
specification="org.ow2.jonas.event.provider.api.IEventProvider">
<callback type="bind" method="bindEventProvider"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment