Skip to content

Commit

Permalink
Format java files in o.e.equinox.cm
Browse files Browse the repository at this point in the history
This was achieved by running:
eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
  -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d`

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson authored and vogella committed Oct 12, 2023
1 parent 9cd2d5d commit 4c8ad37
Show file tree
Hide file tree
Showing 16 changed files with 374 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import org.osgi.service.cm.ConfigurationAdmin;

/**
* Activator start the ConfigurationAdminFactory but also handles passing in the Service
* Registration needed by Asynch threads. Asynch threads are controlled by ConfigurationAdminFactory
* start and stop. It requires some care to handle pending events as the service is registered before
* activating the threads. (see EventDispatcher)
* Activator start the ConfigurationAdminFactory but also handles passing in the
* Service Registration needed by Asynch threads. Asynch threads are controlled
* by ConfigurationAdminFactory start and stop. It requires some care to handle
* pending events as the service is registered before activating the threads.
* (see EventDispatcher)
*/
public class Activator implements BundleActivator {
private static final String EVENT_ADMIN_CLASS = "org.osgi.service.event.EventAdmin"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
import org.osgi.service.cm.ConfigurationPermission;

/**
* ConfigurationAdminFactory provides a Configuration Admin ServiceFactory but more significantly
* launches the whole implementation.
* ConfigurationAdminFactory provides a Configuration Admin ServiceFactory but
* more significantly launches the whole implementation.
*/

public class ConfigurationAdminFactory implements ServiceFactory<ConfigurationAdmin>, BundleListener {

static private final Permission allConfigurationPermission = new ConfigurationPermission("*", ConfigurationPermission.CONFIGURE); //$NON-NLS-1$
static private final Permission allAttributePermission = new ConfigurationPermission("*", ConfigurationPermission.ATTRIBUTE); //$NON-NLS-1$
static private final Permission allConfigurationPermission = new ConfigurationPermission("*", //$NON-NLS-1$
ConfigurationPermission.CONFIGURE);
static private final Permission allAttributePermission = new ConfigurationPermission("*", //$NON-NLS-1$
ConfigurationPermission.ATTRIBUTE);
private final EventDispatcher eventDispatcher;
private final PluginManager pluginManager;
private final LogTracker log;
Expand Down Expand Up @@ -67,7 +69,8 @@ public ConfigurationAdmin getService(Bundle bundle, ServiceRegistration<Configur
}

@Override
public void ungetService(Bundle bundle, ServiceRegistration<ConfigurationAdmin> registration, ConfigurationAdmin service) {
public void ungetService(Bundle bundle, ServiceRegistration<ConfigurationAdmin> registration,
ConfigurationAdmin service) {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
import org.osgi.service.cm.ConfigurationAdmin;

/**
* ConfigurationAdminImpl provides the ConfigurationAdmin service implementation
* ConfigurationAdminImpl provides the ConfigurationAdmin service implementation
*/
class ConfigurationAdminImpl implements ConfigurationAdmin {

private final ConfigurationAdminFactory configurationAdminFactory;
private final String bundleLocation;
private final ConfigurationStore configurationStore;

public ConfigurationAdminImpl(ConfigurationAdminFactory configurationAdminFactory, ConfigurationStore configurationStore, Bundle bundle) {
public ConfigurationAdminImpl(ConfigurationAdminFactory configurationAdminFactory,
ConfigurationStore configurationStore, Bundle bundle) {
this.configurationAdminFactory = configurationAdminFactory;
this.configurationStore = configurationStore;
this.bundleLocation = ConfigurationAdminImpl.getLocation(bundle);
Expand Down Expand Up @@ -67,7 +68,8 @@ public Configuration getFactoryConfiguration(String factoryPid, String name, Str
return internalGetConfiguration(factoryPid, location, true, false, name);
}

private Configuration internalGetConfiguration(String pid, String location, boolean factory, boolean bind, String name) {
private Configuration internalGetConfiguration(String pid, String location, boolean factory, boolean bind,
String name) {
checkPID(pid);
this.configurationAdminFactory.checkConfigurePermission(location, bundleLocation);

Expand Down Expand Up @@ -109,7 +111,7 @@ public Configuration[] listConfigurations(String filterString) throws InvalidSyn
this.configurationAdminFactory.checkConfigurePermission(config.getLocation(), bundleLocation);
}
result.add(config);
}catch (SecurityException e) {
} catch (SecurityException e) {
// ignore;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
import java.util.Map.Entry;

/**
* ConfigurationDictionary holds the actual configuration data and meets the various comparison
* requirements of the Configuration Admin Service specification.
* ConfigurationDictionary holds the actual configuration data and meets the
* various comparison requirements of the Configuration Admin Service
* specification.
*/

public class ConfigurationDictionary extends Dictionary<String, Object> implements Serializable {

private static final long serialVersionUID = -3583299578203095532L;
private static final Collection<Class<?>> simples = Arrays.asList(new Class<?>[] {String.class, Integer.class, Long.class, Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class});
private static final Collection<Class<?>> simpleArrays = Arrays.asList(new Class<?>[] {String[].class, Integer[].class, Long[].class, Float[].class, Double[].class, Byte[].class, Short[].class, Character[].class, Boolean[].class});
private static final Collection<Class<?>> primitiveArrays = Arrays.asList(new Class<?>[] {long[].class, int[].class, short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class});
private static final Collection<Class<?>> simples = Arrays.asList(new Class<?>[] { String.class, Integer.class,
Long.class, Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class });
private static final Collection<Class<?>> simpleArrays = Arrays
.asList(new Class<?>[] { String[].class, Integer[].class, Long[].class, Float[].class, Double[].class,
Byte[].class, Short[].class, Character[].class, Boolean[].class });
private static final Collection<Class<?>> primitiveArrays = Arrays.asList(new Class<?>[] { long[].class,
int[].class, short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class });

static class CaseInsensitiveStringComparator implements Comparator<String>, Serializable {
private static final long serialVersionUID = 6501536810492374044L;
Expand All @@ -40,12 +45,13 @@ public int compare(String s1, String s2) {
}
}

protected final Map<String, Object> configurationProperties = Collections.synchronizedMap(new TreeMap<>(new CaseInsensitiveStringComparator()));
protected final Map<String, Object> configurationProperties = Collections
.synchronizedMap(new TreeMap<>(new CaseInsensitiveStringComparator()));

private static void validateValue(Object value) {
Class<?> clazz = value.getClass();

// Is it in the set of simple types
// Is it in the set of simple types
if (simples.contains(clazz))
return;

Expand Down Expand Up @@ -93,7 +99,8 @@ public Object put(String key, Object value) {
if (key == null || value == null)
throw new NullPointerException();

// Will throw an illegal argument exception if not a valid configuration property type
// Will throw an illegal argument exception if not a valid configuration
// property type
validateValue(value);

return configurationProperties.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public void configurationEvent(ConfigurationEvent event) {
}
String typename = null;
switch (event.getType()) {
case ConfigurationEvent.CM_UPDATED :
typename = CM_UPDATED;
break;
case ConfigurationEvent.CM_DELETED :
typename = CM_DELETED;
break;
default : // do nothing
return;
case ConfigurationEvent.CM_UPDATED:
typename = CM_UPDATED;
break;
case ConfigurationEvent.CM_DELETED:
typename = CM_DELETED;
break;
default: // do nothing
return;
}
String topic = TOPIC + TOPIC_SEPARATOR + typename;
ServiceReference<ConfigurationAdmin> ref = event.getReference();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import org.osgi.service.cm.*;

/**
* ConfigurationImpl provides the Configuration implementation.
* The lock and unlock methods are used for synchronization. Operations outside of
* ConfigurationImpl that expect to have control of the lock should call checkLocked
* ConfigurationImpl provides the Configuration implementation. The lock and
* unlock methods are used for synchronization. Operations outside of
* ConfigurationImpl that expect to have control of the lock should call
* checkLocked
*/
class ConfigurationImpl implements Configuration {
final static String LOCATION_BOUND = "org.eclipse.equinox.cm.location.bound"; //$NON-NLS-1$
Expand All @@ -37,23 +38,24 @@ class ConfigurationImpl implements Configuration {
private final ConfigurationStore configurationStore;
private final String factoryPid;
private final String pid;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private String bundleLocation;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private ConfigurationDictionary dictionary;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private boolean deleted = false;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private boolean bound = false;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private long changeCount;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private Object storageToken;
/** @GuardedBy lock*/
/** @GuardedBy lock */
private boolean readOnly = false;
private final ReentrantLock lock = new ReentrantLock();

public ConfigurationImpl(ConfigurationAdminFactory configurationAdminFactory, ConfigurationStore configurationStore, String factoryPid, String pid, String bundleLocation, boolean bind) {
public ConfigurationImpl(ConfigurationAdminFactory configurationAdminFactory, ConfigurationStore configurationStore,
String factoryPid, String pid, String bundleLocation, boolean bind) {
this.configurationAdminFactory = configurationAdminFactory;
this.configurationStore = configurationStore;
this.factoryPid = factoryPid;
Expand All @@ -63,7 +65,8 @@ public ConfigurationImpl(ConfigurationAdminFactory configurationAdminFactory, Co
this.bound = bind;
}

public ConfigurationImpl(ConfigurationAdminFactory configurationAdminFactory, ConfigurationStore configurationStore, Dictionary<String, ?> dictionary, Object storageToken) {
public ConfigurationImpl(ConfigurationAdminFactory configurationAdminFactory, ConfigurationStore configurationStore,
Dictionary<String, ?> dictionary, Object storageToken) {
this.configurationAdminFactory = configurationAdminFactory;
this.configurationStore = configurationStore;
pid = (String) dictionary.get(Constants.SERVICE_PID);
Expand Down Expand Up @@ -134,7 +137,7 @@ void unbind(Bundle bundle) {
try {
save();
} catch (IOException e) {
// TODO What should we do here? throw a runtime exception or log?
// TODO What should we do here? throw a runtime exception or log?
e.printStackTrace();
}
configurationAdminFactory.notifyLocationChanged(this, callerLocation, factoryPid != null);
Expand Down Expand Up @@ -264,7 +267,8 @@ Dictionary<String, Object> getAllProperties(boolean includeStorageKeys) {
}
}

static void fileAutoProperties(Dictionary<String, Object> dictionary, ConfigurationImpl config, boolean includeLoc, boolean includeStorageKey) {
static void fileAutoProperties(Dictionary<String, Object> dictionary, ConfigurationImpl config, boolean includeLoc,
boolean includeStorageKey) {
dictionary.put(Constants.SERVICE_PID, config.getPid(false));
String factoryPid = config.getFactoryPid(false);
if (factoryPid != null) {
Expand Down Expand Up @@ -305,7 +309,7 @@ public void setBundleLocation(String bundleLocation) {
try {
save();
} catch (IOException e) {
// TODO What should we do here? throw a runtime exception or log?
// TODO What should we do here? throw a runtime exception or log?
e.printStackTrace();
}
configurationAdminFactory.notifyLocationChanged(this, oldLocation, factoryPid != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import org.osgi.service.log.LogService;

/**
* ConfigurationStore manages all active configurations along with persistence. The current
* implementation uses a filestore and serialization of the configuration dictionaries to files
* identified by their pid. Persistence details are in the constructor, saveConfiguration, and
* deleteConfiguration and can be factored out separately if required.
* ConfigurationStore manages all active configurations along with persistence.
* The current implementation uses a filestore and serialization of the
* configuration dictionaries to files identified by their pid. Persistence
* details are in the constructor, saveConfiguration, and deleteConfiguration
* and can be factored out separately if required.
*/
class ConfigurationStore {

Expand Down Expand Up @@ -66,12 +67,14 @@ public ConfigurationStore(ConfigurationAdminFactory configurationAdminFactory, B
dictionary.remove(ConfigurationAdmin.SERVICE_BUNDLELOCATION);
}
}
ConfigurationImpl config = new ConfigurationImpl(configurationAdminFactory, this, dictionary, configurationFile);
ConfigurationImpl config = new ConfigurationImpl(configurationAdminFactory, this, dictionary,
configurationFile);
configurations.put(config.getPid(), config);
} catch (IOException e) {
String message = e.getMessage();
String pid = configurationFileName.substring(0, configurationFileName.length() - 4);
String errorMessage = "{Configuration Admin - pid = " + pid + "} could not be restored." + ((message == null) ? "" : " " + message); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String errorMessage = "{Configuration Admin - pid = " + pid + "} could not be restored." //$NON-NLS-1$//$NON-NLS-2$
+ ((message == null) ? "" : " " + message); //$NON-NLS-1$ //$NON-NLS-2$
configurationAdminFactory.log(LogService.LOG_ERROR, errorMessage);
deleteFile = true;
} catch (ClassNotFoundException e) {
Expand All @@ -81,14 +84,14 @@ public ConfigurationStore(ConfigurationAdminFactory configurationAdminFactory, B
try {
ois.close();
} catch (IOException e) {
// ignore
// ignore
}
}
if (ris != null) {
try {
ris.close();
} catch (IOException e) {
// ignore
// ignore
}
}
}
Expand Down Expand Up @@ -136,14 +139,14 @@ void writeConfigurationFile(File configFile, Dictionary<String, Object> configPr
try {
oos.close();
} catch (IOException e) {
// ignore
// ignore
}
}
if (ros != null) {
try {
ros.close();
} catch (IOException e) {
// ignore
// ignore
}
}
}
Expand Down Expand Up @@ -176,7 +179,8 @@ public synchronized ConfigurationImpl getConfiguration(String pid, String locati
return config;
}

public synchronized ConfigurationImpl getFactoryConfiguration(String factoryPid, String location, boolean bind, String name) {
public synchronized ConfigurationImpl getFactoryConfiguration(String factoryPid, String location, boolean bind,
String name) {
String pid;
if (name == null) {
pid = factoryPid + "-" + new Date().getTime() + "-" + createdPidCount++; //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -188,7 +192,8 @@ public synchronized ConfigurationImpl getFactoryConfiguration(String factoryPid,
}
}

ConfigurationImpl config = new ConfigurationImpl(configurationAdminFactory, this, factoryPid, pid, location, bind);
ConfigurationImpl config = new ConfigurationImpl(configurationAdminFactory, this, factoryPid, pid, location,
bind);
configurations.put(pid, config);
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import org.osgi.util.tracker.ServiceTracker;

/**
* EventDispatcher is responsible for delivering Configuration Events to ConfigurationListeners.
* The originating ConfigAdmin ServiceReference is needed when delivering events. This reference
* is made available by the service factory before returning the service object.
* EventDispatcher is responsible for delivering Configuration Events to
* ConfigurationListeners. The originating ConfigAdmin ServiceReference is
* needed when delivering events. This reference is made available by the
* service factory before returning the service object.
*/

public class EventDispatcher {
Expand Down
Loading

0 comments on commit 4c8ad37

Please sign in to comment.