X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.detached%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fdetached%2Fadmin%2FOpenSession.java;h=48275c75b486ca88267b8bc9fde369a7ad66e484;hb=74904a755b5b344238eafa798419b80c5e74f7ed;hp=11966a97563af5371c5f156e68d92b80d611440f;hpb=8279efc2b92ba454b24ad4d06e7878b00836c07d;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/admin/OpenSession.java b/runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/admin/OpenSession.java index 11966a975..48275c75b 100644 --- a/runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/admin/OpenSession.java +++ b/runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/admin/OpenSession.java @@ -1,6 +1,24 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.detached.admin; +import java.util.List; +import java.util.ArrayList; import java.util.Properties; +import java.util.StringTokenizer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -10,13 +28,13 @@ import org.argeo.slc.detached.DetachedRequest; import org.argeo.slc.detached.DetachedSession; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; public class OpenSession implements DetachedAdminCommand { private final static Log log = LogFactory.getLog(OpenSession.class); public DetachedSession execute(DetachedRequest request, BundleContext bundleContext) { + DetachedSession session = new DetachedSession(); session.setUuid(Long.toString(System.currentTimeMillis())); @@ -28,30 +46,36 @@ public class OpenSession implements DetachedAdminCommand { String refreshedBundles = props .getProperty("slc.detached.refreshedBundles"); if (refreshedBundles != null) { - Bundle[] bundles = bundleContext.getBundles(); - Bundle bundle = null; - for (int i = 0; i < bundles.length; i++) { - if (bundles[i].getSymbolicName().equals(refreshedBundles)) { - bundle = bundles[i]; - } - } + + List refreshedBundleNames = new ArrayList(); + StringTokenizer st = new StringTokenizer(refreshedBundles, ","); + while (st.hasMoreTokens()) { + refreshedBundleNames.add(st.nextElement()); + } + + Bundle[] allBundles = bundleContext.getBundles(); + Bundle[] bundlesToRefresh = new Bundle[refreshedBundleNames.size()]; - if (bundle != null) { - try { - bundle.stop(); - bundle.update(); - bundle.start(); - log.info("Refreshed bundle " + bundle.getSymbolicName()); - } catch (BundleException e) { - throw new DetachedException("Could not refresh bundle " - + bundle.getSymbolicName(), e); - } - } else { - log.warn("Did not find bundle to refresh " + refreshedBundles); + log.debug("Bundles to refresh for DetachedSession:"); + + for(int i = 0; i < bundlesToRefresh.length; ++i) { + bundlesToRefresh[i] = getBundleForName((String)refreshedBundleNames.get(i), allBundles); + if(log.isDebugEnabled()) + log.debug(" " + refreshedBundleNames.get(i)); } + (new MinimalBundlesManager(bundleContext)).upgradeSynchronous(bundlesToRefresh); } return session; } + + private Bundle getBundleForName(String symbolicName, Bundle[] bundles) { + for (int i = 0; i < bundles.length; i++) { + if (symbolicName.equals(bundles[i].getSymbolicName())) { + return bundles[i]; + } + } + throw new DetachedException("No Bundle found for symbolic name " + symbolicName); + } }