Skip to content

Commit

Permalink
Added a instantInit flag to LazyClientStore, removed DefaultSocketSto…
Browse files Browse the repository at this point in the history
…reClientTest, returning DefaultStoreClient for Http protocol
  • Loading branch information
Chinmay Soman committed Sep 11, 2012
1 parent 440832e commit 5cb1249
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 123 deletions.
3 changes: 3 additions & 0 deletions src/java/voldemort/client/AbstractStoreClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public <K, V> StoreClient<K, V> getStoreClient(String storeName,
StoreClient<K, V> client = null;
if(this.config.isDefaultClientEnabled()) {
client = new DefaultStoreClient<K, V>(storeName, resolver, this, 3);
} else if(this.bootstrapUrls.length > 0
&& this.bootstrapUrls[0].getScheme().equals(HttpStoreClientFactory.URL_SCHEME)) {
client = new DefaultStoreClient<K, V>(storeName, resolver, this, 3);
} else {

SchedulerService service = new SchedulerService(config.getAsyncJobThreadPoolSize(),
Expand Down
32 changes: 21 additions & 11 deletions src/java/voldemort/client/LazyStoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,29 @@ public class LazyStoreClient<K, V> implements StoreClient<K, V> {
private StoreClient<K, V> storeClient;

public LazyStoreClient(Callable<StoreClient<K, V>> storeClientThunk) {
this(storeClientThunk, true);
}

/**
* A Hybrid store client which tries to do immediate bootstrap. In case of
* an exception, we fallback to the lazy way of doing initialization.
*
* @param storeClientThunk The callback invoked for doing the actual
* bootstrap
* @param instantInit A boolean flag when set indicates that we should try
* to immediately bootstrap
*/
public LazyStoreClient(Callable<StoreClient<K, V>> storeClientThunk, boolean instantInit) {
this.storeClientThunk = storeClientThunk;

/*
* Although it says Lazy Store Client, we try to bootstrap during
* initialization if we can. If the server isn't up at this time, it
* will be done lazily during the next client API call.
*/
try {
storeClient = initStoreClient();
} catch(Exception e) {
storeClient = null;
e.printStackTrace();
logger.info("Could not bootstrap right away. Trying on the next call ... ");
if(instantInit) {
try {
storeClient = initStoreClient();
} catch(Exception e) {
storeClient = null;
e.printStackTrace();
logger.info("Could not bootstrap right away. Trying on the next call ... ");
}
}
}

Expand Down
104 changes: 0 additions & 104 deletions test/unit/voldemort/client/DefaultSocketStoreClientTest.java

This file was deleted.

19 changes: 11 additions & 8 deletions test/unit/voldemort/client/LazyStoreClientTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2008-2011 LinkedIn, Inc
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand All @@ -16,16 +16,19 @@

package voldemort.client;

import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.concurrent.Callable;

import org.junit.Before;
import org.junit.Test;

import voldemort.serialization.Serializer;
import voldemort.serialization.StringSerializer;
import voldemort.utils.SystemTime;

import java.util.concurrent.Callable;

import static org.mockito.Mockito.*;

/**
*/
public class LazyStoreClientTest extends DefaultStoreClientTest {
Expand Down Expand Up @@ -69,6 +72,6 @@ private LazyStoreClient<String, String> newLazyStoreClient(final StoreClientFact
public StoreClient<String, String> call() throws Exception {
return factory.getStoreClient("test");
}
});
}, false);
}
}

0 comments on commit 5cb1249

Please sign in to comment.