Merge branch '1.2.x'
This commit is contained in:
commit
b1f8a692a8
|
|
@ -17,7 +17,7 @@
|
|||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
|
|||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
|
||||
org.eclipse.jdt.core.formatter.indentation.size=8
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,7 +18,6 @@ package org.springframework.boot.actuate.metrics.writer;
|
|||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* A {@link MetricWriter} that publishes the metric updates on a {@link MessageChannel}.
|
||||
|
|
@ -26,13 +25,10 @@ import org.springframework.messaging.support.MessageBuilder;
|
|||
* carry an additional header "metricName" with the name of the metric in it.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @see MetricWriterMessageHandler
|
||||
*/
|
||||
public class MessageChannelMetricWriter implements MetricWriter {
|
||||
|
||||
private static final String METRIC_NAME = "metricName";
|
||||
|
||||
private final String DELETE = "delete";
|
||||
|
||||
private final MessageChannel channel;
|
||||
|
||||
public MessageChannelMetricWriter(MessageChannel channel) {
|
||||
|
|
@ -41,20 +37,17 @@ public class MessageChannelMetricWriter implements MetricWriter {
|
|||
|
||||
@Override
|
||||
public void increment(Delta<?> delta) {
|
||||
this.channel.send(MessageBuilder.withPayload(delta)
|
||||
.setHeader(METRIC_NAME, delta.getName()).build());
|
||||
this.channel.send(MetricMessage.forIncrement(delta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Metric<?> value) {
|
||||
this.channel.send(MessageBuilder.withPayload(value)
|
||||
.setHeader(METRIC_NAME, value.getName()).build());
|
||||
this.channel.send(MetricMessage.forSet(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(String metricName) {
|
||||
this.channel.send(MessageBuilder.withPayload(this.DELETE)
|
||||
.setHeader(METRIC_NAME, metricName).build());
|
||||
this.channel.send(MetricMessage.forReset(metricName));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* 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 License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.metrics.writer;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* A metric message sent via Spring Integration.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class MetricMessage {
|
||||
|
||||
private static final String METRIC_NAME = "metricName";
|
||||
|
||||
private static final String DELETE = "delete";
|
||||
|
||||
private final Message<?> message;
|
||||
|
||||
public MetricMessage(Message<?> message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isReset() {
|
||||
return DELETE.equals(getPayload());
|
||||
}
|
||||
|
||||
public Object getPayload() {
|
||||
return this.message.getPayload();
|
||||
}
|
||||
|
||||
public String getMetricName() {
|
||||
return this.message.getHeaders().get(METRIC_NAME, String.class);
|
||||
}
|
||||
|
||||
public static Message<?> forIncrement(Delta<?> delta) {
|
||||
return forPayload(delta.getName(), delta);
|
||||
}
|
||||
|
||||
public static Message<?> forSet(Metric<?> value) {
|
||||
return forPayload(value.getName(), value);
|
||||
}
|
||||
|
||||
public static Message<?> forReset(String metricName) {
|
||||
return forPayload(metricName, DELETE);
|
||||
}
|
||||
|
||||
private static Message<?> forPayload(String metricName, Object payload) {
|
||||
MessageBuilder<Object> builder = MessageBuilder.withPayload(payload);
|
||||
builder.setHeader(METRIC_NAME, metricName);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.actuate.metrics.writer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
|
|
@ -26,9 +28,12 @@ import org.springframework.messaging.MessagingException;
|
|||
* {@link MetricWriter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @see MessageChannelMetricWriter
|
||||
*/
|
||||
public final class MetricWriterMessageHandler implements MessageHandler {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MetricWriterMessageHandler.class);
|
||||
|
||||
private final MetricWriter observer;
|
||||
|
||||
public MetricWriterMessageHandler(MetricWriter observer) {
|
||||
|
|
@ -37,14 +42,28 @@ public final class MetricWriterMessageHandler implements MessageHandler {
|
|||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
handleMessage(new MetricMessage(message));
|
||||
}
|
||||
|
||||
private void handleMessage(MetricMessage message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload instanceof Delta) {
|
||||
if (message.isReset()) {
|
||||
this.observer.reset(message.getMetricName());
|
||||
}
|
||||
else if (payload instanceof Delta) {
|
||||
Delta<?> value = (Delta<?>) payload;
|
||||
this.observer.increment(value);
|
||||
}
|
||||
else {
|
||||
else if (payload instanceof Metric) {
|
||||
Metric<?> value = (Metric<?>) payload;
|
||||
this.observer.set(value);
|
||||
}
|
||||
else {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Unsupported metric payload "
|
||||
+ (payload == null ? "null" : payload.getClass().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,35 +16,73 @@
|
|||
|
||||
package org.springframework.boot.actuate.metrics.writer;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link MessageChannelMetricWriter} and {@link MetricWriterMessageHandler}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class MessageChannelMetricWriterTests {
|
||||
|
||||
private final MessageChannel channel = mock(MessageChannel.class);
|
||||
@Mock
|
||||
private MessageChannel channel;
|
||||
|
||||
private final MessageChannelMetricWriter observer = new MessageChannelMetricWriter(
|
||||
this.channel);
|
||||
@Mock
|
||||
private MetricWriter observer;
|
||||
|
||||
private MessageChannelMetricWriter writer;
|
||||
|
||||
private MetricWriterMessageHandler handler;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(this.channel.send(any(Message.class))).willAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
MessageChannelMetricWriterTests.this.handler.handleMessage(invocation
|
||||
.getArgumentAt(0, Message.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
this.writer = new MessageChannelMetricWriter(this.channel);
|
||||
this.handler = new MetricWriterMessageHandler(this.observer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageSentOnAdd() {
|
||||
this.observer.increment(new Delta<Integer>("foo", 1));
|
||||
this.writer.increment(new Delta<Integer>("foo", 1));
|
||||
verify(this.channel).send(any(Message.class));
|
||||
verify(this.observer).increment(any(Delta.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageSentOnSet() {
|
||||
this.observer.set(new Metric<Double>("foo", 1d));
|
||||
this.writer.set(new Metric<Double>("foo", 1d));
|
||||
verify(this.channel).send(any(Message.class));
|
||||
verify(this.observer).set(any(Metric.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageSentOnReset() throws Exception {
|
||||
this.writer.reset("foo");
|
||||
verify(this.channel).send(any(Message.class));
|
||||
verify(this.observer).reset("foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import static org.mockito.Mockito.mock;
|
|||
* Tests for {@link JmsAutoConfiguration}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsAutoConfigurationTests {
|
||||
|
||||
|
|
@ -150,11 +151,13 @@ public class JmsAutoConfigurationTests {
|
|||
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
|
||||
assertEquals(DefaultJmsListenerContainerFactory.class,
|
||||
jmsListenerContainerFactory.getClass());
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory)
|
||||
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertFalse("wrong session transacted flag with JTA transactions", listenerContainer.isSessionTransacted());
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
|
||||
.createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertFalse("wrong session transacted flag with JTA transactions",
|
||||
listenerContainer.isSessionTransacted());
|
||||
assertSame(this.context.getBean(JtaTransactionManager.class),
|
||||
new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager"));
|
||||
new DirectFieldAccessor(listenerContainer)
|
||||
.getPropertyValue("transactionManager"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -165,10 +168,12 @@ public class JmsAutoConfigurationTests {
|
|||
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
|
||||
assertEquals(DefaultJmsListenerContainerFactory.class,
|
||||
jmsListenerContainerFactory.getClass());
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory)
|
||||
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertTrue("wrong session transacted flag with no tx manager", listenerContainer.isSessionTransacted());
|
||||
assertNull(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager"));
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
|
||||
.createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertTrue("wrong session transacted flag with no tx manager",
|
||||
listenerContainer.isSessionTransacted());
|
||||
assertNull(new DirectFieldAccessor(listenerContainer)
|
||||
.getPropertyValue("transactionManager"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -178,10 +183,12 @@ public class JmsAutoConfigurationTests {
|
|||
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
|
||||
assertEquals(DefaultJmsListenerContainerFactory.class,
|
||||
jmsListenerContainerFactory.getClass());
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory)
|
||||
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertTrue("wrong session transacted flag with no tx manager", listenerContainer.isSessionTransacted());
|
||||
assertNull(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager"));
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
|
||||
.createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertTrue("wrong session transacted flag with no tx manager",
|
||||
listenerContainer.isSessionTransacted());
|
||||
assertNull(new DirectFieldAccessor(listenerContainer)
|
||||
.getPropertyValue("transactionManager"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -54,20 +54,19 @@ import org.springframework.boot.loader.util.SystemPropertyUtils;
|
|||
* Looks in various places for a properties file to extract loader settings, defaulting to
|
||||
* {@code application.properties} either on the current classpath or in the current
|
||||
* working directory. The name of the properties file can be changed by setting a System
|
||||
* property {@code loader.config.name} (e.g. {@code -Dloader.config.name=foo}
|
||||
* will look for {@code foo.properties}. If that file doesn't exist then tries
|
||||
* property {@code loader.config.name} (e.g. {@code -Dloader.config.name=foo} will look
|
||||
* for {@code foo.properties}. If that file doesn't exist then tries
|
||||
* {@code loader.config.location} (with allowed prefixes {@code classpath:} and
|
||||
* {@code file:} or any valid URL). Once that file is located turns it into
|
||||
* Properties and extracts optional values (which can also be provided overridden as
|
||||
* System properties in case the file doesn't exist):
|
||||
* {@code file:} or any valid URL). Once that file is located turns it into Properties and
|
||||
* extracts optional values (which can also be provided overridden as System properties in
|
||||
* case the file doesn't exist):
|
||||
* <ul>
|
||||
* <li>{@code loader.path}: a comma-separated list of directories to append to the
|
||||
* classpath (containing file resources and/or nested archives in *.jar or *.zip).
|
||||
* Defaults to {@code lib} (i.e. a directory in the current working directory)</li>
|
||||
* <li>{@code loader.main}: the main method to delegate execution to once the class
|
||||
* loader is set up. No default, but will fall back to looking for a
|
||||
* {@code Start-Class} in a {@code MANIFEST.MF}, if there is one in
|
||||
* <code>${loader.home}/META-INF</code>.</li>
|
||||
* Defaults to {@code lib} in your application archive</li>
|
||||
* <li>{@code loader.main}: the main method to delegate execution to once the class loader
|
||||
* is set up. No default, but will fall back to looking for a {@code Start-Class} in a
|
||||
* {@code MANIFEST.MF}, if there is one in <code>${loader.home}/META-INF</code>.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Dave Syer
|
||||
|
|
|
|||
Loading…
Reference in New Issue