remove guava

This commit is contained in:
Spencer Gibb
2015-02-05 10:39:48 -07:00
parent 6ef01e04e3
commit 7b71befab9
13 changed files with 51 additions and 111 deletions

View File

@@ -168,11 +168,6 @@
<version>1.12.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@@ -35,10 +35,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

View File

@@ -35,10 +35,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

View File

@@ -51,10 +51,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

View File

@@ -2,7 +2,6 @@ package org.springframework.cloud.consul.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.common.base.Throwables;
import feign.Param;
import feign.Response;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,6 +15,7 @@ import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/**
* @author Spencer Gibb
*/
@@ -105,7 +105,7 @@ public class EventService {
return objectMapper.readValue(response.body().asInputStream(),
TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, Event.class));
} catch (IOException e) {
Throwables.propagate(e);
rethrowRuntimeException(e);
}
return null;
}

View File

@@ -4,9 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.io.BaseEncoding.base64;
import static org.springframework.util.Base64Utils.*;
/**
* @author Spencer Gibb
@@ -50,21 +48,22 @@ public class Event {
public String getDecoded() {
if (payload == null)
return null;
return new String(base64().decode(payload), UTF_8);
return new String(decodeFromString(payload));
}
@Override
public String toString() {
return toStringHelper(this)
.add("id", id)
.add("name", name)
.add("nodeFilter", nodeFilter)
.add("serviceFilter", serviceFilter)
.add("tagFilter", tagFilter)
.add("version", version)
.add("lTime", lTime)
.add("payload", payload)
.add("decodedPayload", getDecoded())
.toString();
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("Event{");
sb.append("id='").append(id).append('\'');
sb.append(", name='").append(name).append('\'');
sb.append(", nodeFilter='").append(nodeFilter).append('\'');
sb.append(", serviceFilter='").append(serviceFilter).append('\'');
sb.append(", tagFilter='").append(tagFilter).append('\'');
sb.append(", version=").append(version);
sb.append(", lTime=").append(lTime);
sb.append(", payload='").append(payload).append('\'');
sb.append(", decoded='").append(getDecoded()).append('\'');
sb.append('}');
return sb.toString();
}
}

View File

@@ -3,9 +3,7 @@ package org.springframework.cloud.consul.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.io.BaseEncoding.base64;
import static org.springframework.util.Base64Utils.*;
/**
* @author Spencer Gibb
@@ -31,22 +29,7 @@ public class KeyValue {
public String getDecoded() {
if (value == null)
return null;
return new String(base64().decode(value), UTF_8);
return new String(decodeFromString(value));
}
public void setUnencoded(String unencoded) {
setValue(base64().encode(unencoded.getBytes(UTF_8)));
}
@Override
public String toString() {
return toStringHelper(this)
.add("key", key)
.add("value", value)
.add("decodedValue", getDecoded())
.add("createIndex", createIndex)
.add("modifyIndex", modifyIndex)
.add("flags", flags)
.toString();
}
}

View File

@@ -1,6 +1,5 @@
package org.springframework.cloud.consul.client;
import com.google.common.collect.Lists;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -11,6 +10,7 @@ import org.springframework.cloud.consul.model.Check;
import org.springframework.cloud.consul.model.Service;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Arrays;
import java.util.Map;
import static org.junit.Assert.*;
@@ -34,7 +34,7 @@ public class AgentClientIT {
service.setId("test1id");
service.setName("test1Name");
service.setPort(9999);
service.setTags(Lists.newArrayList("test1tag1", "test1tag2"));
service.setTags(Arrays.asList("test1tag1", "test1tag2"));
Check check = new Check();
check.setScript("/usr/local/bin/gtrue");
check.setInterval(60);

View File

@@ -47,10 +47,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,7 +1,5 @@
package org.springframework.cloud.consul.discovery;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
@@ -12,12 +10,10 @@ import org.springframework.cloud.consul.model.Service;
import org.springframework.cloud.consul.model.ServiceNode;
import org.springframework.context.ApplicationContext;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.google.common.collect.Iterables.*;
/**
* @author Spencer Gibb
*/
@@ -58,38 +54,31 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
@Override
public List<ServiceInstance> getInstances(final String serviceId) {
List<ServiceNode> nodes = catalogClient.getServiceNodes(serviceId);
Iterable<ServiceInstance> instances = transform(nodes, new Function<ServiceNode, ServiceInstance>() {
@Nullable
@Override
public ServiceInstance apply(@Nullable ServiceNode node) {
return new DefaultServiceInstance(serviceId, node.getNode(), node.getServicePort());
}
});
List<ServiceInstance> instances = new ArrayList<>();
for (ServiceNode node : nodes) {
instances.add(new DefaultServiceInstance(serviceId, node.getNode(), node.getServicePort()));
}
return Lists.newArrayList(instances);
return instances;
}
@Override
public List<ServiceInstance> getAllInstances() {
Iterable<ServiceInstance> instances = transform(concat(transform(catalogClient.getServices().keySet(), new Function<String, List<ServiceNode>>() {
@Nullable
@Override
public List<ServiceNode> apply(@Nullable String input) {
return catalogClient.getServiceNodes(input);
}
})), new Function<ServiceNode, ServiceInstance>() {
@Nullable
@Override
public ServiceInstance apply(@Nullable ServiceNode input) {
return new DefaultServiceInstance(input.getServiceName(), input.getNode(), input.getServicePort());
}
});
List<ServiceInstance> instances = new ArrayList<>();
return Lists.newArrayList(instances);
for (String serviceId : catalogClient.getServices().keySet()) {
List<ServiceNode> serviceNodes = catalogClient.getServiceNodes(serviceId);
if (serviceNodes != null) {
for (ServiceNode node : serviceNodes) {
instances.add(new DefaultServiceInstance(node.getServiceName(), node.getNode(), node.getServicePort()));
}
}
}
return instances;
}
@Override
public List<String> getServices() {
return Lists.newArrayList(catalogClient.getServices().keySet());
return new ArrayList<>(catalogClient.getServices().keySet());
}
}

View File

@@ -1,6 +1,5 @@
package org.springframework.cloud.consul.discovery;
import com.google.common.base.Throwables;
import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.*;
@@ -15,6 +14,8 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.util.concurrent.ConcurrentHashMap;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/**
* @author Spencer Gibb
*/
@@ -57,7 +58,7 @@ public class ConsulLoadBalancerClient implements LoadBalancerClient {
try {
return request.apply(choose(serviceId));
} catch (Exception e) {
Throwables.propagate(e);
rethrowRuntimeException(e);
return null;
}
}

View File

@@ -1,19 +1,14 @@
package org.springframework.cloud.consul.discovery;
import com.google.common.base.Function;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractServerList;
import org.springframework.cloud.consul.client.CatalogClient;
import org.springframework.cloud.consul.model.ServiceNode;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.google.common.collect.Collections2.transform;
import static com.google.common.collect.Lists.newArrayList;
/**
* @author Spencer Gibb
*/
@@ -58,15 +53,13 @@ public class ConsulServerList extends AbstractServerList<ConsulServer> {
if (nodes == null || nodes.isEmpty()) {
return Collections.EMPTY_LIST;
}
Collection<ConsulServer> servers = transform(nodes, new Function<ServiceNode, ConsulServer>() {
@Nullable
@Override
public ConsulServer apply(@Nullable ServiceNode node) {
ConsulServer server = new ConsulServer(node);
return server;
}
});
return newArrayList(servers);
List<ConsulServer> servers = new ArrayList<>();
for (ServiceNode node : nodes) {
ConsulServer server = new ConsulServer(node);
servers.add(server);
}
return servers;
}
}

View File

@@ -52,10 +52,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>