+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * 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.ArrayList;
import java.util.List;
+import java.util.ArrayList;
import java.util.Properties;
import java.util.StringTokenizer;
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()));
String refreshedBundles = props
.getProperty("slc.detached.refreshedBundles");
if (refreshedBundles != null) {
+
List refreshedBundleNames = new ArrayList();
StringTokenizer st = new StringTokenizer(refreshedBundles, ",");
while (st.hasMoreTokens()) {
refreshedBundleNames.add(st.nextElement());
- }
+ }
- Bundle[] bundles = bundleContext.getBundles();
+ Bundle[] allBundles = bundleContext.getBundles();
+ Bundle[] bundlesToRefresh = new Bundle[refreshedBundleNames.size()];
- List bundlesToRefresh = new ArrayList();
- for (int i = 0; i < bundles.length; i++) {
- if (refreshedBundleNames.contains(bundles[i].getSymbolicName())) {
- bundlesToRefresh.add(bundles[i]);
- }
+ 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));
}
- for (int i = 0; i < bundlesToRefresh.size(); i++) {
- Bundle bundle = (Bundle) bundlesToRefresh.get(i);
- 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);
- }
- }
+ (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);
+ }
}