Modified APIUtil

Modified the osgi contexts and reformatted.
feature/appm-store/pbac
nishadi 7 years ago
parent 3cc15d0df0
commit 4c1d8dfa4d

@ -31,8 +31,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response;
/**
* Holds util methods required for Application-Mgt API component.
@ -41,68 +41,37 @@ public class APIUtil {
private static Log log = LogFactory.getLog(APIUtil.class);
private static ApplicationManager applicationManager;
private static PlatformManager platformManager;
private static LifecycleStateManager lifecycleStateManager;
private static ApplicationReleaseManager applicationReleaseManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static PlatformStorageManager platformStorageManager;
private static CategoryManager categoryManager;
private static CommentsManager commentsManager;
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
synchronized (APIUtil.class) {
if (applicationManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationManager =
(ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
ApplicationManager applicationManager = (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) {
String msg = "Application Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return applicationManager;
}
public static PlatformManager getPlatformManager() {
if (platformManager == null) {
synchronized (APIUtil.class) {
if (platformManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
platformManager =
(PlatformManager) ctx.getOSGiService(PlatformManager.class, null);
PlatformManager platformManager = (PlatformManager) ctx.getOSGiService(PlatformManager.class, null);
if (platformManager == null) {
String msg = "Platform Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return platformManager;
}
public static LifecycleStateManager getLifecycleStateManager() {
if (lifecycleStateManager == null) {
synchronized (APIUtil.class) {
if (lifecycleStateManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
lifecycleStateManager =
(LifecycleStateManager) ctx.getOSGiService(LifecycleStateManager.class, null);
LifecycleStateManager lifecycleStateManager = (LifecycleStateManager) ctx
.getOSGiService(LifecycleStateManager.class, null);
if (lifecycleStateManager == null) {
String msg = "Lifecycle Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return lifecycleStateManager;
}
@ -112,42 +81,31 @@ public class APIUtil {
* @return ApplicationRelease Manager instance in the current osgi context.
*/
public static ApplicationReleaseManager getApplicationReleaseManager() {
if (applicationReleaseManager == null) {
synchronized (APIUtil.class) {
if (applicationReleaseManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationReleaseManager = (ApplicationReleaseManager) ctx
ApplicationReleaseManager applicationReleaseManager = (ApplicationReleaseManager) ctx
.getOSGiService(ApplicationReleaseManager.class, null);
if (applicationReleaseManager == null) {
String msg = "Application Release Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return applicationReleaseManager;
}
/**
* To get the Application Storage Manager from the osgi context.
*
* @return ApplicationStoreManager instance in the current osgi context.
*/
public static ApplicationStorageManager getApplicationStorageManager() {
if (applicationStorageManager == null) {
synchronized (APIUtil.class) {
if (applicationStorageManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationStorageManager = (ApplicationStorageManager) ctx
ApplicationStorageManager applicationStorageManager = (ApplicationStorageManager) ctx
.getOSGiService(ApplicationStorageManager.class, null);
if (applicationStorageManager == null) {
String msg = "Application Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return applicationStorageManager;
}
@ -157,43 +115,30 @@ public class APIUtil {
* @return PlatformStoreManager instance in the current osgi context.
*/
public static PlatformStorageManager getPlatformStorageManager() {
if (platformStorageManager == null) {
synchronized (APIUtil.class) {
if (platformStorageManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
platformStorageManager = (PlatformStorageManager) ctx
PlatformStorageManager platformStorageManager = (PlatformStorageManager) ctx
.getOSGiService(PlatformStorageManager.class, null);
if (platformStorageManager == null) {
String msg = "Platform Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return platformStorageManager;
}
/**
* To get the Category Manager from the osgi context.
*
* @return CategoryManager instance in the current osgi context.
*/
public static CategoryManager getCategoryManager() {
if (categoryManager == null) {
synchronized (APIUtil.class) {
if (categoryManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
CategoryManager categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
if (categoryManager == null) {
String msg = "Category Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return categoryManager;
}
@ -213,41 +158,35 @@ public class APIUtil {
/**
* To get the Subscription Manager from the osgi context.
*
* @return SubscriptionManager instance in the current osgi context.
*/
public static SubscriptionManager getSubscriptionManager() {
if (subscriptionManager == null) {
synchronized (APIUtil.class) {
if (subscriptionManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
subscriptionManager =
(SubscriptionManager) ctx.getOSGiService(SubscriptionManager.class, null);
SubscriptionManager subscriptionManager = (SubscriptionManager) ctx
.getOSGiService(SubscriptionManager.class, null);
if (subscriptionManager == null) {
String msg = "Subscription Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return subscriptionManager;
}
/**
* To get the Comment Manager from the osgi context.
*
* @return CommentsManager instance in the current osgi context.
*/
public static CommentsManager getCommentsManager() {
if (commentsManager == null) {
synchronized (APIUtil.class) {
if (commentsManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null);
CommentsManager commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null);
if (commentsManager == null) {
String msg = "Comments Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return commentsManager;
}
}

Loading…
Cancel
Save