[Minor] cleaned up compiler warnings

This commit is contained in:
Robert von Burg 2014-08-12 15:15:14 +02:00
parent 941665753c
commit 59f03edaf4
20 changed files with 71 additions and 67 deletions

View File

@ -30,6 +30,8 @@ import li.strolch.runtime.configuration.StrolchConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -38,11 +40,6 @@ public class StrolchAgent {
private static final String AGENT_VERSION_PROPERTIES = "/agentVersion.properties"; //$NON-NLS-1$
private static final Logger logger = LoggerFactory.getLogger(StrolchAgent.class);
/**
* the semi-unique id which is incremented on every {@link #getUniqueId()}-method call
*/
private static long uniqueId = System.currentTimeMillis() - 1119953500000l;
private ComponentContainerImpl container;
private StrolchConfiguration strolchConfiguration;
@ -90,7 +87,7 @@ public class StrolchAgent {
this.strolchConfiguration = ConfigurationParser.parseConfiguration(path);
ComponentContainerImpl container = new ComponentContainerImpl(this);
container.setup(strolchConfiguration);
container.setup(this.strolchConfiguration);
this.container = container;
@ -109,13 +106,7 @@ public class StrolchAgent {
* @return Returns the pseudo unique Id to be used during object creation from external services.
*/
public static synchronized String getUniqueId() {
if (uniqueId == Long.MAX_VALUE - 1) {
uniqueId = 0;
}
uniqueId += 1;
return Long.toString(uniqueId);
return StringHelper.getUniqueId();
}
private VersionQueryResult versionQueryResult;

View File

@ -17,6 +17,7 @@ package li.strolch.agent.api;
import static ch.eitchnet.utils.helper.StringHelper.DOT;
import java.text.MessageFormat;
import java.util.concurrent.TimeUnit;
import li.strolch.agent.impl.DataStoreMode;
@ -36,14 +37,14 @@ import ch.eitchnet.utils.dbc.DBC;
*/
public abstract class StrolchRealm {
private static final String PROP_TRY_LOCK_TIME_UNIT = "tryLockTimeUnit";
private static final String PROP_TRY_LOCK_TIME = "tryLockTime";
private static final String PROP_TRY_LOCK_TIME_UNIT = "tryLockTimeUnit"; //$NON-NLS-1$
private static final String PROP_TRY_LOCK_TIME = "tryLockTime"; //$NON-NLS-1$
protected static final Logger logger = LoggerFactory.getLogger(StrolchRealm.class);
private String realm;
private LockHandler lockHandler;
public StrolchRealm(String realm) {
DBC.PRE.assertNotEmpty("RealmName may not be empty!", realm);
DBC.PRE.assertNotEmpty("RealmName may not be empty!", realm); //$NON-NLS-1$
this.realm = realm;
}
@ -52,7 +53,7 @@ public abstract class StrolchRealm {
}
public void lock(StrolchRootElement element) {
DBC.PRE.assertNotNull("Can not lock a null pointer =)", element);
DBC.PRE.assertNotNull("Can not lock a null pointer =)", element); //$NON-NLS-1$
this.lockHandler.lock(element);
}
@ -71,8 +72,8 @@ public abstract class StrolchRealm {
TimeUnit timeUnit = TimeUnit.valueOf(configuration.getString(propTryLockTimeUnit, TimeUnit.SECONDS.name()));
long time = configuration.getLong(propTryLockTime, 10);
logger.info("Using a locking try timeout of " + timeUnit.toSeconds(time) + "s");
this.lockHandler = new DefaultLockHandler(realm, timeUnit, time);
logger.info(MessageFormat.format("Using a locking try timeout of {0}s", timeUnit.toSeconds(time))); //$NON-NLS-1$
this.lockHandler = new DefaultLockHandler(this.realm, timeUnit, time);
}
public abstract DataStoreMode getMode();
@ -88,5 +89,4 @@ public abstract class StrolchRealm {
public abstract ResourceMap getResourceMap();
public abstract OrderMap getOrderMap();
}

View File

@ -401,7 +401,7 @@ public abstract class CachedElementMap<T extends StrolchElement> implements Elem
long daoRemoved = getDao(tx).removeAll();
if (removed != daoRemoved) {
String msg = "Removed {0} elements from cached map, but dao removed {1} elements!";
String msg = "Removed {0} elements from cached map, but dao removed {1} elements!"; //$NON-NLS-1$
logger.error(MessageFormat.format(msg, removed, daoRemoved));
}
@ -429,7 +429,7 @@ public abstract class CachedElementMap<T extends StrolchElement> implements Elem
long daoRemoved = getDao(tx).removeAllBy(type);
if (removed != daoRemoved) {
msg = "Removed {0} elements from cached map for type {1}, but dao removed {3} elements!";
msg = "Removed {0} elements from cached map for type {1}, but dao removed {3} elements!"; //$NON-NLS-1$
logger.error(MessageFormat.format(msg, removed, type, daoRemoved));
}

View File

@ -1,6 +1,9 @@
package li.strolch.agent.impl;
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_ORDER_REF;
import java.text.MessageFormat;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
@ -15,13 +18,13 @@ public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap
public Order getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
if (!refP.getInterpretation().equals(INTERPRETATION_ORDER_REF)) {
throw new StrolchException(refP.getLocator() + " is not an Order reference as its interpretation is not "
+ INTERPRETATION_ORDER_REF);
String msg = "{0} is not an Order reference as its interpretation is not {1}"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getLocator(), INTERPRETATION_ORDER_REF));
}
if (refP.getUom().equals(Parameter.UOM_NONE)) {
throw new StrolchException(refP.getLocator()
+ " is not an Order reference as its UOM is not set to a type!");
String msg = "{0} is not an Order reference as its UOM is not set to a type!"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
}
String type = refP.getUom();

View File

@ -86,7 +86,7 @@ public class CachedRealm extends StrolchRealm {
for (String type : resourceTypes) {
List<Resource> resources = resourceDao.queryAll(type);
for (Resource resource : resources) {
resourceMap.insert(resource, null);
this.resourceMap.insert(resource, null);
nrOfResources++;
}
}
@ -98,7 +98,7 @@ public class CachedRealm extends StrolchRealm {
for (String type : orderTypes) {
List<Order> orders = orderDao.queryAll(type);
for (Order order : orders) {
orderMap.insert(order, null);
this.orderMap.insert(order, null);
nrOfOrders++;
}
}

View File

@ -206,7 +206,7 @@ public class ComponentContainerImpl implements ComponentContainer {
try {
component.stop();
} catch (Exception e) {
msg = "Failed to stop component {0} due to {1}";
msg = "Failed to stop component {0} due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, componentName, e.getMessage());
logger.error(msg, e);
}
@ -232,7 +232,7 @@ public class ComponentContainerImpl implements ComponentContainer {
try {
component.destroy();
} catch (Exception e) {
msg = "Failed to destroy component {0} due to {1}";
msg = "Failed to destroy component {0} due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, componentName, e.getMessage());
logger.error(msg, e);
}
@ -250,7 +250,7 @@ public class ComponentContainerImpl implements ComponentContainer {
RuntimeConfiguration runtimeConfiguration = strolchConfiguration.getRuntimeConfiguration();
Locale locale = runtimeConfiguration.getLocale();
Locale.setDefault(locale);
String localeMsg = "Application {0} is using locale {1}";
String localeMsg = "Application {0} is using locale {1}"; //$NON-NLS-1$
logger.info(MessageFormat.format(localeMsg, runtimeConfiguration.getApplicationName(), Locale.getDefault()));
// set up the container itself

View File

@ -44,9 +44,11 @@ public class DefaultLockHandler implements LockHandler {
private Map<Locator, ReentrantLock> lockMap;
public DefaultLockHandler(String realm, TimeUnit tryLockTimeUnit, long tryLockTime) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm);
DBC.PRE.assertNotNull("TimeUnit must be set!", tryLockTimeUnit);
DBC.PRE.assertNotEquals("try lock time must not be 0", 0, tryLockTime);
DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
DBC.PRE.assertNotNull("TimeUnit must be set!", tryLockTimeUnit); //$NON-NLS-1$
DBC.PRE.assertNotEquals("try lock time must not be 0", 0, tryLockTime); //$NON-NLS-1$
this.realm = realm;
this.tryLockTimeUnit = tryLockTimeUnit;
this.tryLockTime = tryLockTime;
@ -74,7 +76,7 @@ public class DefaultLockHandler implements LockHandler {
Locator locator = element.getLocator();
ReentrantLock lock = this.lockMap.get(locator);
if (lock == null || !lock.isHeldByCurrentThread()) {
logger.error("Trying to unlock not locked element " + locator);
logger.error(MessageFormat.format("Trying to unlock not locked element {0}", locator)); //$NON-NLS-1$
} else {
unlock(lock);
}

View File

@ -57,7 +57,7 @@ public class DefaultRealmHandler extends StrolchComponent implements RealmHandle
@Override
public StrolchRealm getRealm(String realm) throws StrolchException {
DBC.PRE.assertNotEmpty("Realm name must be set!", realm);
DBC.PRE.assertNotEmpty("Realm name must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = this.realms.get(realm);
if (strolchRealm == null) {
String msg = "No realm is configured with the name {0}"; //$NON-NLS-1$

View File

@ -1,6 +1,9 @@
package li.strolch.agent.impl;
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_ORDER_REF;
import java.text.MessageFormat;
import li.strolch.agent.api.OrderMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
@ -15,13 +18,13 @@ public class TransactionalOrderMap extends TransactionalElementMap<Order> implem
public Order getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
if (!refP.getInterpretation().equals(INTERPRETATION_ORDER_REF)) {
throw new StrolchException(refP.getLocator() + " is not an Order reference as its interpretation is not "
+ INTERPRETATION_ORDER_REF);
String msg = "{0} is not an Order reference as its interpretation is not {1}"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getLocator(), INTERPRETATION_ORDER_REF));
}
if (refP.getUom().equals(Parameter.UOM_NONE)) {
throw new StrolchException(refP.getLocator()
+ " is not an Order reference as its UOM is not set to a type!");
String msg = "{0} is not an Order reference as its UOM is not set to a type!"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
}
String type = refP.getUom();

View File

@ -75,11 +75,11 @@ public class TransactionalRealm extends StrolchRealm {
int nrOfResources = 0;
try (StrolchTransaction tx = openTx()) {
nrOfOrders = orderMap.getAllKeys(tx).size();
nrOfOrders = this.orderMap.getAllKeys(tx).size();
}
try (StrolchTransaction tx = openTx()) {
nrOfResources = resourceMap.getAllKeys(tx).size();
nrOfResources = this.resourceMap.getAllKeys(tx).size();
}
long duration = System.nanoTime() - start;

View File

@ -1,6 +1,9 @@
package li.strolch.agent.impl;
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_RESOURCE_REF;
import java.text.MessageFormat;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Resource;
@ -15,13 +18,13 @@ public class TransactionalResourceMap extends TransactionalElementMap<Resource>
public Resource getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
if (!refP.getInterpretation().equals(INTERPRETATION_RESOURCE_REF)) {
throw new StrolchException(refP.getLocator()
+ " is not an Resource reference as its interpretation is not " + INTERPRETATION_RESOURCE_REF);
String msg = "{0} is not an Resource reference as its interpretation is not {1}"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getLocator(), INTERPRETATION_RESOURCE_REF));
}
if (refP.getUom().equals(Parameter.UOM_NONE)) {
throw new StrolchException(refP.getLocator()
+ " is not an Resource reference as its UOM is not set to a type!");
String msg = "{0} is not an Resource reference as its UOM is not set to a type!"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
}
String type = refP.getUom();

View File

@ -98,14 +98,14 @@ public class TransientRealm extends StrolchRealm {
ModelStatistics statistics;
try (StrolchTransaction tx = openTx()) {
InMemoryElementListener elementListener = new InMemoryElementListener(tx);
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, modelFile);
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile);
handler.parseFile();
statistics = handler.getStatistics();
}
String durationS = StringHelper.formatNanoDuration(statistics.durationNanos);
logger.info(MessageFormat.format(
"Loading XML Model file {0} for realm {1} took {2}.", modelFile.getName(), getRealm(), durationS)); //$NON-NLS-1$
"Loading XML Model file {0} for realm {1} took {2}.", this.modelFile.getName(), getRealm(), durationS)); //$NON-NLS-1$
logger.info(MessageFormat.format("Loaded {0} Orders", statistics.nrOfOrders)); //$NON-NLS-1$
logger.info(MessageFormat.format("Loaded {0} Resources", statistics.nrOfResources)); //$NON-NLS-1$
}

View File

@ -247,7 +247,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
public void autoCloseableCommit() {
long start = System.nanoTime();
if (logger.isDebugEnabled()) {
logger.info("Committing TX for realm " + getRealmName() + "..."); //$NON-NLS-1$
logger.info(MessageFormat.format("Committing TX for realm {0}...", getRealmName())); //$NON-NLS-1$
}
try {
@ -269,21 +269,21 @@ public abstract class AbstractTransaction implements StrolchTransaction {
undoCommands();
} catch (Exception e2) {
try {
rollback(txResult);
rollback(this.txResult);
handleRollback(start);
} catch (Exception e1) {
logger.error("Failed to roll back after failing to undo commands: " + e1.getMessage(), e1);
logger.error("Failed to roll back after failing to undo commands: " + e1.getMessage(), e1); //$NON-NLS-1$
}
handleFailure(start, e);
}
try {
rollback(txResult);
rollback(this.txResult);
handleRollback(start);
} catch (Exception e1) {
handleFailure(start, e);
}
String msg = "Strolch Transaction for realm {0} failed due to {1}";
String msg = "Strolch Transaction for realm {0} failed due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getRealmName(), e.getMessage());
throw new StrolchPersistenceException(msg, e);
@ -295,7 +295,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
@Override
public void autoCloseableRollback() {
long start = System.nanoTime();
logger.warn("Rolling back TX for realm " + getRealmName() + "..."); //$NON-NLS-1$
logger.warn(MessageFormat.format("Rolling back TX for realm {0}...", getRealmName())); //$NON-NLS-1$
try {
undoCommands();
rollback(this.txResult);
@ -314,7 +314,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
private void handleCommit(long start, long observerUpdateDuration) {
long end = System.nanoTime();
long txDuration = end - txResult.getStartNanos();
long txDuration = end - this.txResult.getStartNanos();
long closeDuration = end - start;
this.txResult.setState(TransactionState.COMMITTED);
@ -322,13 +322,13 @@ public abstract class AbstractTransaction implements StrolchTransaction {
this.txResult.setCloseDuration(closeDuration);
StringBuilder sb = new StringBuilder();
sb.append("TX for realm ");
sb.append("TX for realm "); //$NON-NLS-1$
sb.append(getRealmName());
sb.append(" was completed after "); //$NON-NLS-1$
sb.append(StringHelper.formatNanoDuration(txDuration));
sb.append(" with close operation taking "); //$NON-NLS-1$
sb.append(StringHelper.formatNanoDuration(closeDuration));
sb.append(" and observer updates took ");
sb.append(" and observer updates took "); //$NON-NLS-1$
sb.append(StringHelper.formatNanoDuration(observerUpdateDuration));
logger.info(sb.toString());
}
@ -355,7 +355,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
this.txResult.setCloseDuration(closeDuration);
StringBuilder sb = new StringBuilder();
sb.append("TX");
sb.append("TX"); //$NON-NLS-1$
sb.append(getRealmName());
sb.append(" has failed after "); //$NON-NLS-1$
sb.append(StringHelper.formatNanoDuration(txDuration));
@ -363,7 +363,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
sb.append(StringHelper.formatNanoDuration(closeDuration));
logger.info(sb.toString());
String msg = "Strolch Transaction for realm {0} failed due to {1}";
String msg = "Strolch Transaction for realm {0} failed due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getRealmName(), e.getMessage());
throw new StrolchPersistenceException(msg, e);
}

View File

@ -22,7 +22,7 @@ import java.util.Map;
public class RuntimeConfiguration extends AbstractionConfiguration {
public static final String PROP_LOCALE = "locale";
public static final String PROP_LOCALE = "locale"; //$NON-NLS-1$
public static final String RUNTIME = "Runtime"; //$NON-NLS-1$
public static final String PATH_CONFIG = "config"; //$NON-NLS-1$
public static final String PATH_DATA = "data"; //$NON-NLS-1$

View File

@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -108,7 +110,7 @@ public class StrolchEnum {
* the localeL to set
*/
public void setLocaleL(Locale localeL) {
this.locale = localeL.getLanguage() + "_" + localeL.getCountry();
this.locale = localeL.getLanguage() + StringHelper.UNDERLINE + localeL.getCountry();
this.localeL = localeL;
}

View File

@ -42,7 +42,7 @@ public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order, Order
}
public <U> InMemoryQuery<Order, U> visit(OrderQuery orderQuery, OrderVisitor<U> orderVisitor) {
DBC.PRE.assertNotNull("OrderVisitor may not be null!", orderVisitor);
DBC.PRE.assertNotNull("OrderVisitor may not be null!", orderVisitor); //$NON-NLS-1$
orderQuery.accept(this);
Navigator<Order> navigator = getNavigator();

View File

@ -80,7 +80,7 @@ public class InMemoryQuery<T extends StrolchElement, U> {
T element = iter.next();
if (this.selector.select(element)) {
U returnValue = this.elementVisitor.visit(element);
DBC.INTERIM.assertNotNull("Visitor may not return null in query!", returnValue);
DBC.INTERIM.assertNotNull("Visitor may not return null in query!", returnValue); //$NON-NLS-1$
result.add(returnValue);
}
}

View File

@ -78,7 +78,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
protected abstract InMemoryQueryVisitor<T, S> newInstance();
private void assertNotAny() {
DBC.INTERIM.assertFalse("Not allowed to use further Selections with Any!", this.any);
DBC.INTERIM.assertFalse("Not allowed to use further Selections with Any!", this.any); //$NON-NLS-1$
}
protected void addSelector(Selector<T> selector) {
@ -88,7 +88,7 @@ public abstract class InMemoryQueryVisitor<T extends GroupedParameterizedElement
@Override
public void visitAny() {
DBC.PRE.assertEmpty("Only one selection allow when using Any!", this.selectors);
DBC.PRE.assertEmpty("Only one selection allow when using Any!", this.selectors); //$NON-NLS-1$
addSelector(new AnySelector<T>());
this.any = true;
}

View File

@ -41,7 +41,7 @@ public class InMemoryResourceQueryVisitor extends InMemoryQueryVisitor<Resource,
}
public <U> InMemoryQuery<Resource, U> visit(ResourceQuery resourceQuery, ResourceVisitor<U> resourceVisitor) {
DBC.PRE.assertNotNull("ResourceVisitor may not be null!", resourceVisitor);
DBC.PRE.assertNotNull("ResourceVisitor may not be null!", resourceVisitor); //$NON-NLS-1$
resourceQuery.accept(this);
Navigator<Resource> navigator = getNavigator();

View File

@ -46,7 +46,7 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
* the privilegeContext to set
*/
public final void setPrivilegeContext(PrivilegeContext privilegeContext) {
DBC.PRE.assertNull("PrivilegeContext is already set!", this.privilegeContext);
DBC.PRE.assertNull("PrivilegeContext is already set!", this.privilegeContext); //$NON-NLS-1$
this.privilegeContext = privilegeContext;
}