30 changed files with 339 additions and 102 deletions
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard 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.thingsboard.server.actors; |
|||
|
|||
public class TbRuleNodeUpdateException extends RuntimeException { |
|||
|
|||
private static final long serialVersionUID = 8209771144711980882L; |
|||
|
|||
public TbRuleNodeUpdateException(String message, Throwable cause) { |
|||
super(message, cause); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard 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.thingsboard.server.common.msg.plugin; |
|||
|
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
|||
import org.thingsboard.server.common.msg.MsgType; |
|||
|
|||
import java.util.Optional; |
|||
|
|||
/** |
|||
* @author Andrew Shvayka |
|||
*/ |
|||
@ToString |
|||
public class RuleNodeUpdatedMsg extends ComponentLifecycleMsg { |
|||
|
|||
public RuleNodeUpdatedMsg(TenantId tenantId, EntityId entityId) { |
|||
super(tenantId, entityId, ComponentLifecycleEvent.UPDATED); |
|||
} |
|||
|
|||
@Override |
|||
public MsgType getMsgType() { |
|||
return MsgType.RULE_NODE_UPDATED_MSG; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard 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.thingsboard.server.queue.discovery; |
|||
|
|||
import lombok.Getter; |
|||
import org.springframework.context.ApplicationEvent; |
|||
|
|||
import java.util.concurrent.atomic.AtomicInteger; |
|||
|
|||
public class TbApplicationEvent extends ApplicationEvent { |
|||
|
|||
private static final long serialVersionUID = 3884264064887765146L; |
|||
|
|||
private static final AtomicInteger sequence = new AtomicInteger(); |
|||
|
|||
@Getter |
|||
private final int sequenceNumber; |
|||
|
|||
public TbApplicationEvent(Object source) { |
|||
super(source); |
|||
sequenceNumber = sequence.incrementAndGet(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard 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.thingsboard.server.queue.discovery; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.context.ApplicationListener; |
|||
|
|||
import java.util.concurrent.locks.Lock; |
|||
import java.util.concurrent.locks.ReentrantLock; |
|||
|
|||
@Slf4j |
|||
public abstract class TbApplicationEventListener<T extends TbApplicationEvent> implements ApplicationListener<T> { |
|||
|
|||
private int lastProcessedSequenceNumber = Integer.MIN_VALUE; |
|||
private final Lock seqNumberLock = new ReentrantLock(); |
|||
|
|||
@Override |
|||
public void onApplicationEvent(T event) { |
|||
boolean validUpdate = false; |
|||
seqNumberLock.lock(); |
|||
try { |
|||
if (event.getSequenceNumber() > lastProcessedSequenceNumber) { |
|||
validUpdate = true; |
|||
lastProcessedSequenceNumber = event.getSequenceNumber(); |
|||
} |
|||
} finally { |
|||
seqNumberLock.unlock(); |
|||
} |
|||
if (validUpdate) { |
|||
onTbApplicationEvent(event); |
|||
} else { |
|||
log.info("Application event ignored due to invalid sequence number ({} > {}). Event: {}", lastProcessedSequenceNumber, event.getSequenceNumber(), event); |
|||
} |
|||
} |
|||
|
|||
protected abstract void onTbApplicationEvent(T event); |
|||
|
|||
|
|||
} |
|||
Loading…
Reference in new issue