Fixed checkStyle and ErrorProne warns
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2017 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.persistence.h2;
|
||||
|
||||
import org.h2.mvstore.MVMap;
|
||||
|
||||
@@ -41,17 +41,18 @@ public class H2PersistentStore implements IStore {
|
||||
|
||||
public H2PersistentStore(IConfig props, ScheduledExecutorService scheduler) {
|
||||
this.storePath = props.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, "");
|
||||
this.autosaveInterval = Integer.parseInt(props.getProperty(BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME, "30"));
|
||||
final String autosaveProp = props.getProperty(BrokerConstants.AUTOSAVE_INTERVAL_PROPERTY_NAME, "30");
|
||||
this.autosaveInterval = Integer.parseInt(autosaveProp);
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
@SuppressWarnings("FutureReturnValueIgnored")
|
||||
@Override
|
||||
public void initStore() {
|
||||
LOG.info("Initializing H2 store");
|
||||
if (storePath == null || storePath.isEmpty()) {
|
||||
LOG.warn("H2 store file path is empty, using in-memory store");
|
||||
mvStore = MVStore.open(null);
|
||||
|
||||
} else {
|
||||
mvStore = new MVStore.Builder()
|
||||
.fileName(storePath)
|
||||
@@ -60,13 +61,9 @@ public class H2PersistentStore implements IStore {
|
||||
}
|
||||
|
||||
LOG.info("Scheduling H2 commit task");
|
||||
scheduler.scheduleWithFixedDelay(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.debug("Committing to H2");
|
||||
mvStore.commit();
|
||||
}
|
||||
scheduler.scheduleWithFixedDelay(() -> {
|
||||
LOG.debug("Committing to H2");
|
||||
mvStore.commit();
|
||||
}, this.autosaveInterval, this.autosaveInterval, TimeUnit.SECONDS);
|
||||
|
||||
messageStore = new H2MessagesStore(mvStore);
|
||||
@@ -78,7 +75,6 @@ public class H2PersistentStore implements IStore {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,7 +71,7 @@ public class H2SessionsStore implements ISessionsStore, ISubscriptionsStore {
|
||||
LOG.info("Adding new subscription CId={}, topics={}", newSubscription.getClientId(),
|
||||
newSubscription.getTopicFilter());
|
||||
final String clientID = newSubscription.getClientId();
|
||||
final MVMap<Object, Object> sessionSubscriptions = this.mvStore.openMap("subscriptions_" + clientID);
|
||||
final MVMap<Object, Object> sessionSubscriptions = this.mvStore.openMap(subscriptionsMapName(clientID));
|
||||
sessionSubscriptions.put(newSubscription.getTopicFilter(), newSubscription);
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
@@ -84,10 +84,10 @@ public class H2SessionsStore implements ISessionsStore, ISubscriptionsStore {
|
||||
@Override
|
||||
public void removeSubscription(Topic topicFilter, String clientID) {
|
||||
LOG.info("Removing subscription. CId={}, topics={}", clientID, topicFilter);
|
||||
if (!this.mvStore.hasMap("subscriptions_" + clientID)) {
|
||||
if (!this.mvStore.hasMap(subscriptionsMapName(clientID))) {
|
||||
return;
|
||||
}
|
||||
final MVMap<Object, Object> sessionsSubscriptions = this.mvStore.openMap("subscriptions_" + clientID);
|
||||
final MVMap<Object, Object> sessionsSubscriptions = this.mvStore.openMap(subscriptionsMapName(clientID));
|
||||
sessionsSubscriptions.remove(topicFilter);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Subscription has been removed. CId={}, topics={}, clientSubscriptions={}", clientID,
|
||||
@@ -98,10 +98,10 @@ public class H2SessionsStore implements ISessionsStore, ISubscriptionsStore {
|
||||
@Override
|
||||
public void wipeSubscriptions(String sessionID) {
|
||||
LOG.info("Wiping subscriptions. CId={}", sessionID);
|
||||
if (!this.mvStore.hasMap("subscriptions_" + sessionID)) {
|
||||
if (!this.mvStore.hasMap(subscriptionsMapName(sessionID))) {
|
||||
return;
|
||||
}
|
||||
final MVMap<Object, Object> subscriptions = this.mvStore.openMap("subscriptions_" + sessionID);
|
||||
final MVMap<Object, Object> subscriptions = this.mvStore.openMap(subscriptionsMapName(sessionID));
|
||||
this.mvStore.removeMap(subscriptions);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Subscriptions have been removed. CId={}, clientSubscriptions={}", sessionID, subscriptions);
|
||||
@@ -113,7 +113,8 @@ public class H2SessionsStore implements ISessionsStore, ISubscriptionsStore {
|
||||
LOG.debug("Retrieving existing subscriptions...");
|
||||
List<Subscription> subscriptions = new ArrayList<>();
|
||||
for (String clientID : this.sessions.keySet()) {
|
||||
ConcurrentMap<Topic, Subscription> clientSubscriptions = this.mvStore.openMap("subscriptions_" + clientID);
|
||||
final String mapName = subscriptionsMapName(clientID);
|
||||
ConcurrentMap<Topic, Subscription> clientSubscriptions = this.mvStore.openMap(mapName);
|
||||
subscriptions.addAll(clientSubscriptions.values());
|
||||
}
|
||||
LOG.debug("Existing subscriptions has been retrieved Result={}", subscriptions);
|
||||
@@ -122,7 +123,7 @@ public class H2SessionsStore implements ISessionsStore, ISubscriptionsStore {
|
||||
|
||||
@Override
|
||||
public Collection<Subscription> listClientSubscriptions(String clientID) {
|
||||
ConcurrentMap<Topic, Subscription> clientSubscriptions = this.mvStore.openMap("subscriptions_" + clientID);
|
||||
ConcurrentMap<Topic, Subscription> clientSubscriptions = this.mvStore.openMap(subscriptionsMapName(clientID));
|
||||
if (clientSubscriptions == null) {
|
||||
throw new IllegalStateException("Asking for subscriptions of not persisted client: " + clientID);
|
||||
}
|
||||
@@ -130,10 +131,15 @@ public class H2SessionsStore implements ISessionsStore, ISubscriptionsStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subscription reload(Subscription subcription) {
|
||||
ConcurrentMap<Topic, Subscription> clientSubscriptions = this.mvStore.openMap("subscriptions_" + subcription.getClientId());
|
||||
LOG.debug("Retrieving subscriptions CId={}, subscriptions={}", subcription.getClientId(), clientSubscriptions);
|
||||
return clientSubscriptions.get(subcription.getTopicFilter());
|
||||
public Subscription reload(Subscription subscription) {
|
||||
final String subscriptionsMapName = subscriptionsMapName(subscription.getClientId());
|
||||
ConcurrentMap<Topic, Subscription> clientSubscriptions = this.mvStore.openMap(subscriptionsMapName);
|
||||
LOG.debug("Retrieving subscriptions CId={}, subscriptions={}", subscription.getClientId(), clientSubscriptions);
|
||||
return clientSubscriptions.get(subscription.getTopicFilter());
|
||||
}
|
||||
|
||||
private String subscriptionsMapName(String clientId) {
|
||||
return "subscriptions_" + clientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2017 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.persistence.h2;
|
||||
|
||||
import io.moquette.BrokerConstants;
|
||||
@@ -61,12 +76,12 @@ public class H2PersistentQueueTest {
|
||||
H2PersistentQueue<String> sut = new H2PersistentQueue<>(this.mvStore, "test");
|
||||
|
||||
int numIterations = 10000000;
|
||||
for (int i=0; i < numIterations; i++) {
|
||||
for (int i = 0; i < numIterations; i++) {
|
||||
sut.add("Hello");
|
||||
}
|
||||
mvStore.commit();
|
||||
|
||||
for (int i=0; i < numIterations; i++) {
|
||||
for (int i = 0; i < numIterations; i++) {
|
||||
assertEquals("Hello", sut.poll());
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ public class H2SessionsStoreTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieve1000ExpiredSessionPerformance() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public void testRetrieve1000ExpiredSessionPerformance() throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
H2SessionsStore sessionsStore = (H2SessionsStore) storageService.sessionsStore();
|
||||
|
||||
final ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||
|
||||
Reference in New Issue
Block a user