Skip to content

Commit

Permalink
Enabling the channels auto-start configuration through it's manager M…
Browse files Browse the repository at this point in the history
…Bean.
  • Loading branch information
aaron-mcgrath-adp authored and sebastien-belin-adp committed Jul 25, 2024
1 parent 59b34e4 commit f528b88
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import javax.management.MalformedObjectNameException;
import javax.management.Notification;
import javax.management.ObjectName;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.adaptris.core.Channel;
Expand All @@ -47,6 +49,7 @@ public class ChannelManager extends ComponentManagerImpl<Channel> implements Cha
private transient Set<WorkflowRuntimeManager> workflowManagers;
private transient ObjectName myObjectName = null;
private transient Set<ChildRuntimeInfoComponent> childRuntimeInfoComponents;
private transient boolean autoStart;

private ChannelManager() {
super();
Expand All @@ -62,6 +65,7 @@ public ChannelManager(Channel c, AdapterManager owner) throws MalformedObjectNam
this();
channel = c;
parent = owner;
autoStart = BooleanUtils.toBooleanDefaultIfNull(c.getAutoStart(), true);
initMembers();
if (!skipBackRef) {
parent.addChild(this);
Expand Down Expand Up @@ -240,6 +244,11 @@ public Collection<BaseComponentMBean> getAllDescendants() {
public String getParentId() {
return parent.getUniqueId();
}

@Override
public boolean getAutoStart() {
return autoStart;
}

@Override
public ObjectName getParentObjectName() throws MalformedObjectNameException {
Expand Down Expand Up @@ -372,4 +381,5 @@ protected String getNotificationType(ComponentNotificationType type) {
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ public interface ChannelManagerMBean extends AdapterComponentMBean, ParentRuntim
* @throws MalformedObjectNameException upon ObjectName errors.
*/
boolean removeWorkflow(String id) throws CoreException, IllegalStateException, MalformedObjectNameException;

/**
* Will return the configured auto-start boolean.
* Auto-start determines if this channel should be started when the Adapter starts.
*
* @return true if the channel is set to start with the Adapter
*/
boolean getAutoStart();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,11 @@ public String getWrappedComponentClassname() {
return Channel.class.getCanonicalName();
}

@Override
public boolean getAutoStart() {
return true;
}

}

private class AdapterChild extends StubBaseComponentMBean implements ChildRuntimeInfoComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,37 @@ public void testGetParentId() throws Exception {
adapter.requestClose();
}
}

@Test
public void testGetAutoStart() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
Channel channel = createChannel(getName(), 0);
channel.setAutoStart(false);
try {
AdapterManager adapterManager = new AdapterManager(adapter);
ChannelManager channelManager = new ChannelManager(channel, adapterManager);
assertFalse(channelManager.getAutoStart());
}
finally {
adapter.requestClose();
}
}

@Test
public void testGetDefaultAutoStart() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
Channel channel = createChannel(getName(), 0);
try {
AdapterManager adapterManager = new AdapterManager(adapter);
ChannelManager channelManager = new ChannelManager(channel, adapterManager);
assertTrue(channelManager.getAutoStart());
}
finally {
adapter.requestClose();
}
}

@Test
public void testProxyEquality() throws Exception {
Expand Down

0 comments on commit f528b88

Please sign in to comment.