Remove Lombok

This commit is contained in:
Dave Syer
2016-03-18 11:22:20 +00:00
parent 5a14eda63a
commit c6c70962c5
10 changed files with 303 additions and 51 deletions

View File

@@ -54,11 +54,6 @@
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View File

@@ -18,13 +18,10 @@ package org.springframework.cloud.bus;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
/**
* @author Dave Syer
*
*/
@Data
@ConfigurationProperties("spring.cloud.bus")
public class BusProperties {
@@ -54,23 +51,68 @@ public class BusProperties {
*/
private boolean enabled = true;
@Data
public Env getEnv() {
return env;
}
public Refresh getRefresh() {
return refresh;
}
public Ack getAck() {
return ack;
}
public Trace getTrace() {
return trace;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public static class Env {
/**
* Flag to switch off environment change events (default on).
*/
private boolean enabled = true;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
@Data
public static class Refresh {
/**
* Flag to switch off refresh events (default on).
*/
private boolean enabled = true;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
@Data
public static class Ack {
/**
* Flag to switch off acks (default on).
@@ -80,14 +122,37 @@ public class BusProperties {
* Service that wants to listen to acks. By default null (meaning all services).
*/
private String destinationService;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getDestinationService() {
return destinationService;
}
public void setDestinationService(String destinationService) {
this.destinationService = destinationService;
}
}
@Data
public static class Trace {
/**
* Flag to switch on tracing of acks (default off).
*/
private boolean enabled = false;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
}

View File

@@ -16,9 +16,6 @@
package org.springframework.cloud.bus.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* An event that signals an ack of a specific {@link RemoteApplicationEvent}. These events
* can be monitored by any applications that want to audit the responses to bus events.
@@ -29,8 +26,6 @@ import lombok.EqualsAndHashCode;
*
*/
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
public class AckRemoteApplicationEvent extends RemoteApplicationEvent {
private final String ackId;
@@ -53,4 +48,57 @@ public class AckRemoteApplicationEvent extends RemoteApplicationEvent {
this.ackId = ackId;
this.event = type;
}
public String getAckId() {
return ackId;
}
public String getAckDestinationService() {
return ackDestinationService;
}
public Class<? extends RemoteApplicationEvent> getEvent() {
return event;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((ackDestinationService == null) ? 0
: ackDestinationService.hashCode());
result = prime * result + ((ackId == null) ? 0 : ackId.hashCode());
result = prime * result + ((event == null) ? 0 : event.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AckRemoteApplicationEvent other = (AckRemoteApplicationEvent) obj;
if (ackDestinationService == null) {
if (other.ackDestinationService != null)
return false;
}
else if (!ackDestinationService.equals(other.ackDestinationService))
return false;
if (ackId == null) {
if (other.ackId != null)
return false;
}
else if (!ackId.equals(other.ackId))
return false;
if (event == null) {
if (other.event != null)
return false;
}
else if (!event.equals(other.event))
return false;
return true;
}
}

View File

@@ -2,8 +2,8 @@ package org.springframework.cloud.bus.event;
import java.util.Map;
import lombok.extern.apachecommons.CommonsLog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentManager;
import org.springframework.context.ApplicationListener;
@@ -11,9 +11,11 @@ import org.springframework.context.ApplicationListener;
/**
* @author Spencer Gibb
*/
@CommonsLog
public class EnvironmentChangeListener implements
ApplicationListener<EnvironmentChangeRemoteApplicationEvent> {
public class EnvironmentChangeListener
implements ApplicationListener<EnvironmentChangeRemoteApplicationEvent> {
private static Log log = LogFactory.getLog(EnvironmentChangeListener.class);
@Autowired
private EnvironmentManager env;

View File

@@ -2,15 +2,10 @@ package org.springframework.cloud.bus.event;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author Spencer Gibb
*/
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEvent {
private final Map<String, String> values;
@@ -27,4 +22,34 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv
this.values = values;
}
public Map<String, String> getValues() {
return values;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((values == null) ? 0 : values.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
EnvironmentChangeRemoteApplicationEvent other = (EnvironmentChangeRemoteApplicationEvent) obj;
if (values == null) {
if (other.values != null)
return false;
}
else if (!values.equals(other.values))
return false;
return true;
}
}

View File

@@ -2,18 +2,19 @@ package org.springframework.cloud.bus.event;
import java.util.Arrays;
import lombok.extern.apachecommons.CommonsLog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.endpoint.RefreshEndpoint;
import org.springframework.context.ApplicationListener;
/**
* @author Spencer Gibb
*/
@CommonsLog
public class RefreshListener implements
ApplicationListener<RefreshRemoteApplicationEvent> {
public class RefreshListener
implements ApplicationListener<RefreshRemoteApplicationEvent> {
private static Log log = LogFactory.getLog(RefreshListener.class);
private RefreshEndpoint endpoint;
public RefreshListener(RefreshEndpoint endpoint) {
@@ -23,6 +24,7 @@ public class RefreshListener implements
@Override
public void onApplicationEvent(RefreshRemoteApplicationEvent event) {
String[] keys = endpoint.refresh();
log.info("Received remote refresh request. Keys refreshed " + Arrays.asList(keys));
log.info(
"Received remote refresh request. Keys refreshed " + Arrays.asList(keys));
}
}

View File

@@ -7,15 +7,10 @@ import org.springframework.context.ApplicationEvent;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author Spencer Gibb
*/
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonIgnoreProperties("source")
public abstract class RemoteApplicationEvent extends ApplicationEvent {
@@ -47,4 +42,58 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent {
protected RemoteApplicationEvent(Object source, String originService) {
this(source, originService, null);
}
public String getOriginService() {
return originService;
}
public String getDestinationService() {
return destinationService;
}
public String getId() {
return id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((destinationService == null) ? 0 : destinationService.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result
+ ((originService == null) ? 0 : originService.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RemoteApplicationEvent other = (RemoteApplicationEvent) obj;
if (destinationService == null) {
if (other.destinationService != null)
return false;
}
else if (!destinationService.equals(other.destinationService))
return false;
if (id == null) {
if (other.id != null)
return false;
}
else if (!id.equals(other.id))
return false;
if (originService == null) {
if (other.originService != null)
return false;
}
else if (!originService.equals(other.originService))
return false;
return true;
}
}

View File

@@ -5,9 +5,6 @@ import org.springframework.context.ApplicationEvent;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* An event signalling that a remote event was sent somewhere in the system. This is not
* itself a {@link RemoteApplicationEvent}, so it isn't sent over the bus, instead it is
@@ -19,8 +16,6 @@ import lombok.EqualsAndHashCode;
* @author Dave Syer
*/
@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonIgnoreProperties("source")
public class SentApplicationEvent extends ApplicationEvent {
@@ -52,4 +47,73 @@ public class SentApplicationEvent extends ApplicationEvent {
this.destinationService = destinationService;
this.id = id;
}
public Class<? extends RemoteApplicationEvent> getType() {
return type;
}
public void setType(Class<? extends RemoteApplicationEvent> type) {
this.type = type;
}
public String getOriginService() {
return originService;
}
public String getDestinationService() {
return destinationService;
}
public String getId() {
return id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((destinationService == null) ? 0 : destinationService.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result
+ ((originService == null) ? 0 : originService.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SentApplicationEvent other = (SentApplicationEvent) obj;
if (destinationService == null) {
if (other.destinationService != null)
return false;
}
else if (!destinationService.equals(other.destinationService))
return false;
if (id == null) {
if (other.id != null)
return false;
}
else if (!id.equals(other.id))
return false;
if (originService == null) {
if (other.originService != null)
return false;
}
else if (!originService.equals(other.originService))
return false;
if (type == null) {
if (other.type != null)
return false;
}
else if (!type.equals(other.type))
return false;
return true;
}
}

View File

@@ -3,20 +3,21 @@ package org.springframework.cloud.bus.event;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.context.event.EventListener;
import lombok.extern.apachecommons.CommonsLog;
/**
* A listener for sends and acks of remote application events. Inserts a record for each
* signal in the {@link TraceRepository}.
*
* @author Dave Syer
*/
@CommonsLog
public class TraceListener {
private static Log log = LogFactory.getLog(TraceListener.class);
private TraceRepository repository;
public TraceListener(TraceRepository repository) {

View File

@@ -19,10 +19,9 @@ public class SubtypeModuleTests {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new SubtypeModule(MyRemoteApplicationEvent.class));
RemoteApplicationEvent event = mapper
.readValue(
"{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}",
RemoteApplicationEvent.class);
RemoteApplicationEvent event = mapper.readValue(
"{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}",
RemoteApplicationEvent.class);
assertTrue("event is wrong type", event instanceof MyRemoteApplicationEvent);
MyRemoteApplicationEvent myEvent = MyRemoteApplicationEvent.class.cast(event);
assertEquals("originService was wrong", "myorigin", myEvent.getOriginService());
@@ -34,6 +33,7 @@ public class SubtypeModuleTests {
assertTrue("event is wrong type", event instanceof AnotherRemoteApplicationEvent);
}
@SuppressWarnings("serial")
@JsonTypeName("my")
public static class MyRemoteApplicationEvent extends RemoteApplicationEvent {
@SuppressWarnings("unused")
@@ -50,6 +50,7 @@ public class SubtypeModuleTests {
}
}
@SuppressWarnings("serial")
@JsonTypeName("another")
public static class AnotherRemoteApplicationEvent extends RemoteApplicationEvent {
@SuppressWarnings("unused")