From b5c0d648cf147d3709eb78d98011f38e07aee723 Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 13 Nov 2009 01:25:44 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835694 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/store/DuplicateRecordException.java | 56 +++++++++++++ .../apache/tuscany/sca/store/RecoveryListener.java | 46 +++++++++++ .../java/org/apache/tuscany/sca/store/Store.java | 96 ++++++++++++++++++++++ .../apache/tuscany/sca/store/StoreException.java | 57 +++++++++++++ .../tuscany/sca/store/StoreExpirationEvent.java | 71 ++++++++++++++++ .../org/apache/tuscany/sca/store/StoreMonitor.java | 71 ++++++++++++++++ .../tuscany/sca/store/StoreReadException.java | 56 +++++++++++++ .../tuscany/sca/store/StoreWriteException.java | 56 +++++++++++++ 8 files changed, 509 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java create mode 100644 sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java (limited to 'sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store') diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java new file mode 100644 index 0000000000..7d5cd6c54b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + +/** + * thrown when a record already exists during an insert operation + * + * @version $Rev$ $Date$ + */ +public class DuplicateRecordException extends StoreWriteException { + private static final long serialVersionUID = 3116253222569378447L; + + /** + * {@inheritDoc} + */ + public DuplicateRecordException() { + super(); + } + + /** + * {@inheritDoc} + */ + public DuplicateRecordException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public DuplicateRecordException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public DuplicateRecordException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java new file mode 100644 index 0000000000..9d965a3369 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + +import java.util.UUID; + +/** + * Implementations receive callback events during a store recovery operation + * + * @version $Rev$ $Date$ + */ +public interface RecoveryListener { + + /** + * Signals the start of a recovery + */ + void onBegin(); + + /** + * Received when a record is recovered + * + * @param id + */ + void onRecord(UUID id); + + /** + * Signals the end of recovery + */ + void onEnd(); +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java new file mode 100644 index 0000000000..b15cde066a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Implementations provide a persistent store for runtime data such as conversational state. A persistent store could be + * implemented in a durable fashion using JDBC or a journaling system, or using a non-durable mechanism such as an + * in-memory map. + * + * @version $Rev$ $Date$ + */ +public interface Store extends EventPublisher { + + /* Used to indicate an the default expiration offset for records for the store */ + long DEFAULT_EXPIRATION_OFFSET = -1; + + /* Used to indicate an entry should not expire */ + long NEVER = -2; + + /** + * Adds the given record to the store. Implementations may choose different strategies for writing data such as + * write-through or write-behind. + * + * @param owner the instance owner + * @param id the unique id of the record + * @param object the object representing the data to write + * @param expiration the time in milliseconds when the entry expires + * @throws StoreWriteException if an error occurs during the write operation + */ + void insertRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException; + + /** + * Updates a given record in the store, overwriting previous information. + * + * @param owner the instance owner + * @param id the unique id of the record + * @param object the object representing the data to write + * @param expiration the time in milliseconds when the entry expires + * @throws StoreWriteException + */ + void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException; + + /** + * Returns the deserialized object in the store corresponding to the given id + * + * @param owner the instance owner + * @param id the unique id of the record + * @return the deserialized object or null if one is not found + * @throws StoreReadException + */ + Object readRecord(RuntimeComponent owner, String id) throws StoreReadException; + + /** + * Removes a record from the store + * + * @param owner the instance owner + * @param id the unique id of the record + * @throws StoreWriteException + */ + void removeRecord(RuntimeComponent owner, String id) throws StoreWriteException; + + /** + * Removes all records from the store + * + * @throws StoreWriteException + */ + void removeRecords() throws StoreWriteException; + + /** + * Initiates a recovery operation, for example during restart after a crash + * + * @param listener the listener to receive recovery callback events + * @throws StoreReadException + */ + void recover(RecoveryListener listener) throws StoreReadException; + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java new file mode 100644 index 0000000000..24eaddd3e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + + +/** + * Represents a generic exception thrown by a Store + * + * @version $Rev$ $Date$ + */ +public class StoreException extends Exception { + private static final long serialVersionUID = -319152147419962709L; + + /** + * {@inheritDoc} + */ + public StoreException() { + super(); + } + + /** + * {@inheritDoc} + */ + public StoreException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public StoreException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public StoreException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java new file mode 100644 index 0000000000..5c1a3ca79d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Fired when a store implementation expires a resource + * + * @version $Rev$ $Date$ + */ +public class StoreExpirationEvent implements Event { + private Object source; + private RuntimeComponent owner; + private Object instance; + + /** + * Constructor. + * + * @param source the source of the event + * @param owner the owner of the expiring object + * @param instance the expiring object + */ + public StoreExpirationEvent(Object source, RuntimeComponent owner, Object instance) { + assert source != null; + assert owner != null; + assert instance != null; + this.source = source; + this.owner = owner; + this.instance = instance; + } + + public Object getSource() { + return source; + } + + /** + * Returns the owner of the expiring object. + * + * @return the owner of the expiring object. + */ + public RuntimeComponent getOwner() { + return owner; + } + + /** + * Returns the expiring object. + * + * @return the expiring object. + */ + public Object getInstance() { + return instance; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java new file mode 100644 index 0000000000..4bc7facf39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + + +/** + * A generic monitor interface for services to log events + * + * @version $Rev$ $Date$ + */ +public interface StoreMonitor { + + /** + * Signals the service has started + * + * @param msg + */ + void start(String msg); + + /** + * Signals the service has been shutdown + * + * @param msg + */ + void stop(String msg); + + /** + * Fired when recovery is started + */ + + void beginRecover(); + + /** + * Fired when recovery is completed + */ + + void endRecover(); + + /** + * Fired when a record is processed during recovery + * + * @param recordId the id of the record being recovered + */ + + void recover(Object recordId); + + /** + * Signals an error event + * + * @param e the error + */ + + void error(Throwable e); + +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java new file mode 100644 index 0000000000..c2346bddca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + +/** + * Thrown when an error occurs reading from persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreReadException extends StoreException { + private static final long serialVersionUID = -8624542082121467271L; + + /** + * {@inheritDoc} + */ + public StoreReadException() { + super(); + } + + /** + * {@inheritDoc} + */ + public StoreReadException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public StoreReadException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public StoreReadException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java new file mode 100644 index 0000000000..b37519b31c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.5.2/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.sca.store; + +/** + * Thrown when an error occurs writing to persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreWriteException extends StoreException { + private static final long serialVersionUID = 5539070473942048555L; + + /** + * {@inheritDoc} + */ + public StoreWriteException() { + super(); + } + + /** + * {@inheritDoc} + */ + public StoreWriteException(String message, Throwable cause) { + super(message, cause); + } + + /** + * {@inheritDoc} + */ + public StoreWriteException(String message) { + super(message); + } + + /** + * {@inheritDoc} + */ + public StoreWriteException(Throwable cause) { + super(cause); + } +} -- cgit v1.2.3