-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DROOLS-7479] Split StoredEvent from StoredFact
- removing handleId as no longer used
- Loading branch information
Showing
10 changed files
with
251 additions
and
75 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ty/drools-reliability-core/src/main/java/org/drools/reliability/core/BaseStoredEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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.drools.reliability.core; | ||
|
||
import org.drools.core.common.DefaultEventHandle; | ||
import org.drools.core.common.InternalWorkingMemoryEntryPoint; | ||
import org.drools.core.rule.accessor.FactHandleFactory; | ||
|
||
public abstract class BaseStoredEvent extends BaseStoredObject implements StoredEvent { | ||
|
||
protected final long timestamp; | ||
protected final long duration; | ||
|
||
protected BaseStoredEvent(boolean propagated, long timestamp, long duration) { | ||
super(propagated); | ||
this.timestamp = timestamp; | ||
this.duration = duration; | ||
} | ||
|
||
@Override | ||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
@Override | ||
public long getDuration() { | ||
return duration; | ||
} | ||
|
||
@Override | ||
public void repropagate(InternalWorkingMemoryEntryPoint ep) { | ||
FactHandleFactory fhFactory = ep.getHandleFactory(); | ||
DefaultEventHandle eFh = fhFactory.createEventFactHandle(fhFactory.getNextId(), getObject(), fhFactory.getNextRecency(), ep, timestamp, duration); | ||
ep.insert(eFh); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...s-reliability-core/src/main/java/org/drools/reliability/core/SerializableStoredEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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.drools.reliability.core; | ||
|
||
import java.io.Serializable; | ||
|
||
public class SerializableStoredEvent extends BaseStoredEvent { | ||
|
||
private final Serializable object; | ||
|
||
public SerializableStoredEvent(Object object, boolean propagated, long timestamp, long duration) { | ||
super(propagated, timestamp, duration); | ||
if (!(object instanceof Serializable)) { | ||
throw new IllegalArgumentException("Object must be serializable : " + object.getClass().getCanonicalName()); | ||
} | ||
this.object = (Serializable) object; | ||
} | ||
|
||
@Override | ||
public Serializable getObject() { | ||
return object; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SerializableStoredEvent{" + | ||
"object=" + object + | ||
", propagated=" + propagated + | ||
", timestamp=" + timestamp + | ||
", duration=" + duration + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...bility/drools-reliability-core/src/main/java/org/drools/reliability/core/StoredEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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.drools.reliability.core; | ||
|
||
public interface StoredEvent extends StoredObject { | ||
|
||
@Override | ||
default boolean isEvent() { | ||
return true; | ||
} | ||
|
||
long getTimestamp(); | ||
|
||
long getDuration(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...inispan/src/main/java/org/drools/reliability/infinispan/proto/ProtoStreamStoredEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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.drools.reliability.infinispan.proto; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
import org.drools.reliability.core.BaseStoredEvent; | ||
import org.drools.reliability.core.BaseStoredObject; | ||
import org.drools.reliability.core.ReliabilityRuntimeException; | ||
import org.drools.reliability.core.StorageManagerFactory; | ||
import org.drools.reliability.infinispan.InfinispanStorageManager; | ||
import org.infinispan.protostream.ProtobufUtil; | ||
import org.infinispan.protostream.SerializationContext; | ||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
import org.infinispan.protostream.types.protobuf.AnySchema; | ||
|
||
/** | ||
* This class is used to store objects in Infinispan using ProtoStream. | ||
* This class inherits Serializable from BaseStoredEvent, but it uses ProtoStream instead of Java serialization. | ||
*/ | ||
public class ProtoStreamStoredEvent extends BaseStoredEvent { | ||
|
||
private final transient Object object; | ||
|
||
private final String typeUrl; | ||
private final transient AnySchema.Any protoObject; | ||
|
||
public ProtoStreamStoredEvent(Object object, boolean propagated, long timestamp, long duration) { | ||
super(propagated, timestamp, duration); | ||
|
||
this.object = object; | ||
|
||
this.typeUrl = object.getClass().getCanonicalName(); | ||
SerializationContext serializationContext = ((InfinispanStorageManager) StorageManagerFactory.get().getStorageManager()).getSerializationContext(); | ||
byte[] objectBytes; | ||
try { | ||
objectBytes = ProtobufUtil.toByteArray(serializationContext, object); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
this.protoObject = new AnySchema.Any(typeUrl, objectBytes); | ||
} | ||
|
||
@ProtoFactory | ||
public ProtoStreamStoredEvent(AnySchema.Any protoObject, boolean propagated, long timestamp, long duration) { | ||
super(propagated, timestamp, duration); | ||
|
||
this.protoObject = protoObject; | ||
this.typeUrl = protoObject.getTypeUrl(); | ||
|
||
SerializationContext serializationContext = ((InfinispanStorageManager) StorageManagerFactory.get().getStorageManager()).getSerializationContext(); | ||
try { | ||
Class<?> type = Class.forName(this.typeUrl); | ||
this.object = ProtobufUtil.fromByteArray(serializationContext, protoObject.getValue(), type); | ||
} catch (IOException | ClassNotFoundException e) { | ||
throw new ReliabilityRuntimeException(e); | ||
} | ||
} | ||
|
||
@ProtoField(value = 1, required = true) | ||
public AnySchema.Any getProtoObject() { | ||
return protoObject; | ||
} | ||
|
||
@Override | ||
@ProtoField(value = 2, required = true) | ||
public boolean isPropagated() { | ||
return propagated; | ||
} | ||
|
||
@ProtoField(value = 3, required = true) | ||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
@ProtoField(value = 4, required = true) | ||
public long getDuration() { | ||
return duration; | ||
} | ||
|
||
@Override | ||
public Object getObject() { | ||
return object; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ProtoStreamStoredObject{" + | ||
"object=" + object + | ||
", propagated=" + propagated + | ||
", timestamp=" + timestamp + | ||
", duration=" + duration + | ||
", typeUrl='" + typeUrl + '\'' + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.