Skip to content

Commit

Permalink
Reformat code in HsmSet.java
Browse files Browse the repository at this point in the history
  • Loading branch information
svemeyer committed Jul 28, 2023
1 parent a3faf8c commit 108f2f5
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions modules/dcache/src/main/java/org/dcache/pool/nearline/HsmSet.java
Expand Up @@ -18,6 +18,8 @@
package org.dcache.pool.nearline;

import static java.util.Collections.unmodifiableSet;
import static java.util.Objects.requireNonNull;
import static org.dcache.util.Exceptions.messageOrClassName;

import com.google.common.collect.Maps;
import diskCacheV111.util.FileNotInCacheException;
Expand Down Expand Up @@ -66,9 +68,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;

import static java.util.Objects.requireNonNull;
import static org.dcache.util.Exceptions.messageOrClassName;

/**
* An HsmSet encapsulates information about attached HSMs. The HsmSet also acts as a cell command
* interpreter, allowing the user to add, remove or alter the information.
Expand All @@ -85,18 +84,20 @@
*/
public class HsmSet
implements CellCommandListener, CellSetupProvider, CellLifeCycleAware,
CellDynamicCommandProvider {
CellDynamicCommandProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(HsmSet.class);

/**
* Nearline storage provides that are part of the dCache on located in standard plugin classpath.
* Nearline storage provides that are part of the dCache on located in standard plugin
* classpath.
*/
private static final Map<String, NearlineStorageProvider> EMBEDDED_PROVIDERS =
ServiceLoader.load(NearlineStorageProvider.class)
.stream()
.map(Provider::get)
.collect(Collectors.toUnmodifiableMap(NearlineStorageProvider::getName, Function.identity()));
.stream()
.map(Provider::get)
.collect(Collectors.toUnmodifiableMap(NearlineStorageProvider::getName,
Function.identity()));

/**
* Nearline storage provides that dynamically at the runtime.
Expand All @@ -118,6 +119,7 @@ public class HsmSet

/**
* Looks for an embedded on dynamically loaded configured provided.
*
* @param name of the nearline storage provider to find.
* @return nearline storage provider.
* @throws IllegalArgumentException if provider with a given name not found.
Expand Down Expand Up @@ -300,6 +302,7 @@ public NearlineStorage getNearlineStorage() {
/**
* Call the NearlineStorage start method. This method may only be called once and must be
* called before calling any other method, other than {@literal configure}.
*
* @throws IOException if the underlying NearlinePlugin threw an exception.
*/
public void start() throws IOException {
Expand Down Expand Up @@ -389,7 +392,6 @@ public String call() throws CommandException {
writer.header("PROVIDER").left("provider").space();
writer.header("DESCRIPTION").left("description");


var f = new File(path);
if (!f.exists()) {
throw new CommandException(1, "No such directory: " + path);
Expand Down Expand Up @@ -434,9 +436,10 @@ public String call() throws CommandException {
}

@Command(name = "hsm unload provider", hint = "Unload user provided nearline storage provider",
description = "Unloads user loaded provide. After unloading, the provider can be used anymore."
+ " The system behaviour in undefined, if plugin is removed while corresponding hsm still"
+ " in use.")
description =
"Unloads user loaded provide. After unloading, the provider can be used anymore."
+ " The system behaviour in undefined, if plugin is removed while corresponding hsm still"
+ " in use.")
public class UnloadProvider implements Callable<String> {

@Argument(usage = "Provider name to unload")
Expand All @@ -458,7 +461,8 @@ public String call() throws CommandException {
try {
((URLClassLoader) (p.getClass().getClassLoader())).close();
} catch (IOException e) {
throw new CommandException(1, "Can't unload " + provider + " : " + e.getMessage());
throw new CommandException(1,
"Can't unload " + provider + " : " + e.getMessage());
}
}

Expand Down Expand Up @@ -535,7 +539,7 @@ public String call() throws CommandException {
info.start();
} catch (IOException e) {
throw new CommandException(1, "Nearline plugin failed on start: "
+ messageOrClassName(e));
+ messageOrClassName(e));
}
_hsm.put(instance, info);
}
Expand Down Expand Up @@ -698,9 +702,9 @@ public synchronized void afterSetup() {

/* Remove the stores that are not in the new configuration.
*/
Iterator<Map.Entry<String,HsmInfo>> iterator = _hsm.entrySet().iterator();
Iterator<Map.Entry<String, HsmInfo>> iterator = _hsm.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String,HsmInfo> entry = iterator.next();
Map.Entry<String, HsmInfo> entry = iterator.next();

if (_newConfig.containsKey(entry.getKey())) {
continue;
Expand All @@ -718,7 +722,8 @@ public synchronized void afterSetup() {
try {
hsm.refresh();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Error configuring hsm \"" + hsm.getInstance() + "\": " + e.getMessage());
throw new IllegalArgumentException(
"Error configuring hsm \"" + hsm.getInstance() + "\": " + e.getMessage());
}
}

Expand All @@ -733,13 +738,13 @@ public synchronized void afterSetup() {
entry.getValue().start();
} catch (IOException e) {
LOGGER.warn(
AlarmMarkerFactory.getMarker(
PredefinedAlarm.HSM_STARTUP_FAILED,
_poolName,
instance),
"Removing HSM \"{}\" as it failed to start: {}",
instance,
messageOrClassName(e));
AlarmMarkerFactory.getMarker(
PredefinedAlarm.HSM_STARTUP_FAILED,
_poolName,
instance),
"Removing HSM \"{}\" as it failed to start: {}",
instance,
messageOrClassName(e));
itr.remove();
}
}
Expand All @@ -763,13 +768,13 @@ public void afterStart() {
} catch (IOException e) {
String instance = entry.getKey();
LOGGER.warn(
AlarmMarkerFactory.getMarker(
PredefinedAlarm.HSM_STARTUP_FAILED,
_poolName,
instance),
"Removing HSM \"{}\" as it failed to start: {}",
instance,
messageOrClassName(e));
AlarmMarkerFactory.getMarker(
PredefinedAlarm.HSM_STARTUP_FAILED,
_poolName,
instance),
"Removing HSM \"{}\" as it failed to start: {}",
instance,
messageOrClassName(e));
itr.remove();
}
}
Expand Down

0 comments on commit 108f2f5

Please sign in to comment.