View | Details | Raw Unified | Return to bug 379865 | Differences between
and this patch

Collapse All | Expand All

(-)core/framework/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java (-13 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2010 IBM Corporation and others.
2
 * Copyright (c) 2004, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 948-989 Link Here
948
	 * @return List<ServiceRegistrationImpl>
948
	 * @return List<ServiceRegistrationImpl>
949
	 */
949
	 */
950
	private List<ServiceRegistrationImpl<?>> lookupServiceRegistrations(String clazz, Filter filter) {
950
	private List<ServiceRegistrationImpl<?>> lookupServiceRegistrations(String clazz, Filter filter) {
951
		List<ServiceRegistrationImpl<?>> result;
951
		List<ServiceRegistrationImpl<?>> registrationsCopy;
952
		synchronized (this) {
952
		synchronized (this) {
953
			if (clazz == null) { /* all services */
953
			if (clazz == null) { /* all services */
954
				result = allPublishedServices;
954
				registrationsCopy = allPublishedServices;
955
			} else {
955
			} else {
956
				/* services registered under the class name */
956
				/* services registered under the class name */
957
				result = publishedServicesByClass.get(clazz);
957
				registrationsCopy = publishedServicesByClass.get(clazz);
958
			}
958
			}
959
959
960
			if ((result == null) || result.isEmpty()) {
960
			if ((registrationsCopy == null) || registrationsCopy.isEmpty()) {
961
				@SuppressWarnings("unchecked")
961
				@SuppressWarnings("unchecked")
962
				List<ServiceRegistrationImpl<?>> empty = Collections.EMPTY_LIST;
962
				List<ServiceRegistrationImpl<?>> empty = Collections.EMPTY_LIST;
963
				return empty;
963
				return empty;
964
			}
964
			}
965
965
966
			result = new ArrayList<ServiceRegistrationImpl<?>>(result); /* make a new list since we don't want to change the real list */
966
			registrationsCopy = new ArrayList<ServiceRegistrationImpl<?>>(registrationsCopy); /* make a new list since we don't want to change the real list */
967
		}
967
		}
968
968
969
		if (filter == null) {
969
		if (filter == null) {
970
			return result;
970
			return registrationsCopy;
971
		}
971
		}
972
972
973
		for (Iterator<ServiceRegistrationImpl<?>> iter = result.iterator(); iter.hasNext();) {
973
		// bug 379865: use an additive approach instead of removal 
974
			ServiceRegistrationImpl<?> registration = iter.next();
974
		// to help with performance when removing large numbers of registrations
975
		List<ServiceRegistrationImpl<?>> filteredRegistrations = new ArrayList<ServiceRegistrationImpl<?>>(registrationsCopy.size());
976
		for (ServiceRegistrationImpl<?> registration : registrationsCopy) {
975
			ServiceReferenceImpl<?> reference;
977
			ServiceReferenceImpl<?> reference;
976
			try {
978
			try {
977
				reference = registration.getReferenceImpl();
979
				reference = registration.getReferenceImpl();
978
			} catch (IllegalStateException e) {
980
			} catch (IllegalStateException e) {
979
				iter.remove(); /* service was unregistered after we left the synchronized block above */
981
				/* service was unregistered after we left the synchronized block above */
980
				continue;
982
				continue;
981
			}
983
			}
982
			if (!filter.match(reference)) {
984
			if (filter.match(reference)) {
983
				iter.remove();
985
				filteredRegistrations.add(registration);
984
			}
986
			}
985
		}
987
		}
986
		return result;
988
		return filteredRegistrations;
987
	}
989
	}
988
990
989
	/**
991
	/**

Return to bug 379865