X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.detached%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fdetached%2Fadmin%2FOpenSession.java;h=8a583d3a94e58c633bd95409297be38c1ffad2b7;hb=5fcacdb600e4c9e765cb93b46132932662832c1b;hp=f6522e4238ff9918a252b970906cc632b9d99629;hpb=cb6c9116f75a6941f6f968bf2757260ae8a5dbda;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 f6522e423..8a583d3a9 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,7 +1,23 @@ +/* + * Copyright (C) 2010 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.ArrayList; import java.util.List; +import java.util.ArrayList; import java.util.Properties; import java.util.StringTokenizer; @@ -19,7 +35,6 @@ public class OpenSession implements DetachedAdminCommand { public DetachedSession execute(DetachedRequest request, BundleContext bundleContext) { - MinimalBundlesManager bundlesManager = new MinimalBundlesManager(bundleContext); DetachedSession session = new DetachedSession(); session.setUuid(Long.toString(System.currentTimeMillis())); @@ -32,43 +47,36 @@ public class OpenSession implements DetachedAdminCommand { 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 { - bundlesManager.upgradeSynchronous(bundle); -// bundle.stop(); -// bundle.update(); -// bundle.start(); - log.info("Refreshed bundle " + bundle.getSymbolicName()); - -// try { -// Thread.sleep(2000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } - - } catch (Exception 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); + } }