Skip to content

Commit

Permalink
Refactored NodeChannel into separate channel and node channel control…
Browse files Browse the repository at this point in the history
… objects. Created basic unit tests for node control save, and NodeConcurrencyFilter headers.
  • Loading branch information
mhanes committed Sep 8, 2009
1 parent 81f4c2a commit d69ace8
Show file tree
Hide file tree
Showing 19 changed files with 584 additions and 155 deletions.
Expand Up @@ -39,7 +39,7 @@ public class Channel {
private int maxBatchToSend;

private boolean enabled;

private String batchAlgorithm = "default";

public Channel() {
Expand Down Expand Up @@ -96,26 +96,28 @@ public int getMaxBatchToSend() {
public void setMaxBatchToSend(int maxBatchToSend) {
this.maxBatchToSend = maxBatchToSend;
}

/**
* Check to see if this channel id matches one of the channels in the collection
* Check to see if this channel id matches one of the channels in the
* collection
*
* @return true if a match is found
*/
public boolean isInList(Collection<? extends Channel> channels) {
public boolean isInList(Collection<? extends NodeChannel> channels) {
if (channels != null) {
for (Channel channel : channels) {
for (NodeChannel channel : channels) {
if (channel.getId().equals(id)) {
return true;
}
}
}
return false;
}

public void setBatchAlgorithm(String batchAlgorithm) {
this.batchAlgorithm = batchAlgorithm;
}

public String getBatchAlgorithm() {
return batchAlgorithm;
}
Expand Down
Expand Up @@ -26,13 +26,13 @@ public class DataMetaData {
private Data data;
private Table table;
private TriggerRouter trigger;
private Channel channel;
private NodeChannel nodeChannel;

public DataMetaData(Data data, Table table, TriggerRouter trigger, Channel channel) {
public DataMetaData(Data data, Table table, TriggerRouter trigger, NodeChannel nodeChannel) {
this.data = data;
this.table = table;
this.trigger = trigger;
this.channel = channel;
this.nodeChannel = nodeChannel;
}

public Data getData() {
Expand All @@ -58,13 +58,13 @@ public TriggerRouter getTrigger() {
public void setTrigger(TriggerRouter trigger) {
this.trigger = trigger;
}
public Channel getChannel() {
return channel;

public NodeChannel getNodeChannel() {
return nodeChannel;
}
public void setChannel(Channel channel) {
this.channel = channel;

public void setNodeChannel(NodeChannel nodeChannel) {
this.nodeChannel = nodeChannel;
}

public TriggerHistory getTriggerHistory() {
Expand Down
110 changes: 73 additions & 37 deletions symmetric/src/main/java/org/jumpmind/symmetric/model/NodeChannel.java
Expand Up @@ -20,75 +20,111 @@

package org.jumpmind.symmetric.model;

import java.util.List;
import java.util.Date;

public class NodeChannel extends Channel {
public class NodeChannel {

private static final long serialVersionUID = -2493052366767513160L;
private Channel channel;
private NodeChannelControl nodeChannelControl;

String nodeId;
public NodeChannel() {
channel = new Channel();
nodeChannelControl = new NodeChannelControl();
}

private boolean ignored = false;
public NodeChannel(String channelId) {
channel = new Channel();
nodeChannelControl = new NodeChannelControl();
channel.setId(channelId);
}

private boolean suspended = false;
public String getId() {
return channel.getId();
}

private List<NodeGroupChannelWindow> nodeGroupChannelWindows;
public int getMaxBatchSize() {
return channel.getMaxBatchSize();
}

public NodeChannel() {
public void setMaxBatchSize(int maxBatchSize) {
channel.setMaxBatchSize(maxBatchSize);
}

public NodeChannel(String channelId) {
this.setId(channelId);
public int getMaxBatchToSend() {
return channel.getMaxBatchToSend();
}

public boolean isIgnored() {
return ignored;
public void setMaxBatchToSend(int maxBatchToSend) {
channel.setMaxBatchToSend(maxBatchToSend);
}

public int getProcessingOrder() {
return channel.getProcessingOrder();
}

public void setIgnored(boolean ignore) {
this.ignored = ignore;
public String getBatchAlgorithm() {
return channel.getBatchAlgorithm();
}

public void setBatchAlgorithm(String batchAlgorithm) {
channel.setBatchAlgorithm(batchAlgorithm);
}

public void setEnabled(boolean enabled) {
channel.setEnabled(enabled);
}

public boolean isEnabled() {
return channel.isEnabled();
}

public boolean isSuspended() {
return suspended;
return nodeChannelControl.isSuspended();
}

public void setSuspended(boolean suspend) {
this.suspended = suspend;
public boolean isIgnored() {
return nodeChannelControl.isIgnored();
}

public String getNodeId() {
return nodeId;
return nodeChannelControl.getNodeId();
}

public void setNodeId(String nodeId) {
this.nodeId = nodeId;
nodeChannelControl.setNodeId(nodeId);
}

public void setNodeGroupChannelWindows(List<NodeGroupChannelWindow> nodeGroupChannelWindows) {
this.nodeGroupChannelWindows = nodeGroupChannelWindows;
public void setLastExtractedTime(Date lastExtractedTime) {
nodeChannelControl.setLastExtractedTime(lastExtractedTime);
}

public List<NodeGroupChannelWindow> getNodeGroupChannelWindows() {
return nodeGroupChannelWindows;
public Date getLastExtractedTime() {
return nodeChannelControl.getLastExtractedTime();
}

/**
* If {@link NodeGroupChannelWindow}s are defined for this channel, then check to
* see if the time (according to the offset passed in) is within on of the configured windows.
*/
public boolean inTimeWindow(String timezoneOffset) {
if (nodeGroupChannelWindows != null && nodeGroupChannelWindows.size() > 0) {
for (NodeGroupChannelWindow window : nodeGroupChannelWindows) {
if (window.inTimeWindow(timezoneOffset)) {
return true;
}
}
return false;
} else {
return true;
}
public void setIgnored(boolean ignored) {
nodeChannelControl.setIgnored(ignored);
}

public void setProcessingOrder(int priority) {
channel.setProcessingOrder(priority);
}

public void setId(String id) {
channel.setId(id);
}

public void setSuspended(boolean suspended) {
nodeChannelControl.setSuspended(suspended);
}

public Channel getChannel() {
return channel;
}

public NodeChannelControl getNodeChannelControl() {
return nodeChannelControl;
}

}
@@ -0,0 +1,69 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/

package org.jumpmind.symmetric.model;

import java.util.Date;

public class NodeChannelControl {

private static final long serialVersionUID = -2493052366767513160L;

private String nodeId = null;

public String getNodeId() {
return nodeId;
}

public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}

public boolean isIgnored() {
return ignored;
}

public void setIgnored(boolean ignored) {
this.ignored = ignored;
}

public boolean isSuspended() {
return suspended;
}

public void setSuspended(boolean suspended) {
this.suspended = suspended;
}

public Date getLastExtractedTime() {
return lastExtractedTime;
}

public void setLastExtractedTime(Date lastExtractedTime) {
this.lastExtractedTime = lastExtractedTime;
}

private boolean ignored = false;

private boolean suspended = false;

private Date lastExtractedTime = null;

}
Expand Up @@ -24,9 +24,8 @@

public class DefaultBatchAlgorithm implements IBatchAlgorithm {

public boolean isBatchComplete(OutgoingBatch batch, DataMetaData dataMetaData,
IRouterContext routingContext) {
return batch.getDataEventCount() >= dataMetaData.getChannel().getMaxBatchSize()
public boolean isBatchComplete(OutgoingBatch batch, DataMetaData dataMetaData, IRouterContext routingContext) {
return batch.getDataEventCount() >= dataMetaData.getNodeChannel().getMaxBatchSize()
&& routingContext.isEncountedTransactionBoundary();
}

Expand Down
Expand Up @@ -24,9 +24,8 @@

public class NonTransactionalBatchAlgorithm implements IBatchAlgorithm {

public boolean isBatchComplete(OutgoingBatch batch, DataMetaData dataMetaData,
IRouterContext routingContext) {
return batch.getDataEventCount() >= dataMetaData.getChannel().getMaxBatchSize();
public boolean isBatchComplete(OutgoingBatch batch, DataMetaData dataMetaData, IRouterContext routingContext) {
return batch.getDataEventCount() >= dataMetaData.getNodeChannel().getMaxBatchSize();
}

public boolean isAutoRegister() {
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.jumpmind.symmetric.model.Channel;
import org.jumpmind.symmetric.model.DataEventAction;
import org.jumpmind.symmetric.model.NodeChannel;
import org.jumpmind.symmetric.model.NodeGroupChannelWindow;
import org.jumpmind.symmetric.model.NodeGroupLink;

/**
Expand All @@ -39,18 +40,28 @@ public interface IConfigurationService {

public void saveChannel(Channel channel);

public void saveChannel(NodeChannel channel);

public void saveNodeChannel(NodeChannel channel);

public void saveNodeChannelControl(NodeChannel channel);

public void deleteChannel(Channel channel);

public List<NodeGroupChannelWindow> getNodeGroupChannelWindows(String nodeGroupId, String channelId);

public DataEventAction getDataEventActionsByGroupId(String sourceGroupId, String targetGroupId);

public List<NodeChannel> getChannels();

public List<NodeChannel> getChannels(String nodeId);

public NodeChannel getChannel(String channelId);

public List<NodeChannel> getNodeChannels();

public List<NodeChannel> getNodeChannels(String nodeId);

public NodeChannel getNodeChannel(String channelId);

public NodeChannel getNodeChannel(String channelId, String nodeId);

public void reloadChannels();

public void autoConfigDatabase(boolean force);

}

0 comments on commit d69ace8

Please sign in to comment.