Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AAE0D200BB5 for ; Sat, 22 Oct 2016 09:18:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A972D160ADF; Sat, 22 Oct 2016 07:18:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 49354160AFC for ; Sat, 22 Oct 2016 09:18:47 +0200 (CEST) Received: (qmail 17772 invoked by uid 500); 22 Oct 2016 07:18:46 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 17687 invoked by uid 99); 22 Oct 2016 07:18:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Oct 2016 07:18:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 304A4E69A3; Sat, 22 Oct 2016 07:18:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@zest.apache.org Date: Sat, 22 Oct 2016 07:18:48 -0000 Message-Id: <931aa030a1294e7a9c18d77731341797@git.apache.org> In-Reply-To: <905f92c311ff4327b45066692279f972@git.apache.org> References: <905f92c311ff4327b45066692279f972@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/7] zest-java git commit: ZEST-183 : Removing library-eventsourcing. archived-at: Sat, 22 Oct 2016 07:18:49 -0000 http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/UnitOfWorkApplicationEvents.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/UnitOfWorkApplicationEvents.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/UnitOfWorkApplicationEvents.java deleted file mode 100644 index 642b911..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/UnitOfWorkApplicationEvents.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.factory; - -import java.util.ArrayList; -import java.util.List; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; - -/** - * List of events for the current UnitOfWork. This will be updated by the DomainEventFactory. - */ -public class UnitOfWorkApplicationEvents -{ - private List events = new ArrayList(); - - public void add( ApplicationEvent event ) - { - events.add( event ); - } - - public List getEvents() - { - return events; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/package.html deleted file mode 100644 index fd91648..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/factory/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing Application Factory.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayer.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayer.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayer.java deleted file mode 100644 index 6d33fd7..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayer.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.replay; - -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; - -/** - * Service that can replay ApplicationEvents. - */ -public interface ApplicationEventPlayer -{ - /** - * Invoke a domain event on a particular object. The object could - * be the original object, but could also be a service that wants - * to be invoked to handle the event. - * - * @param applicationEvent Application event - * @param object target - * @throws ApplicationEventReplayException if unable to play event - */ - public void playEvent( ApplicationEvent applicationEvent, Object object ) - throws ApplicationEventReplayException; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayerService.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayerService.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayerService.java deleted file mode 100644 index cca1d01..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventPlayerService.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.replay; - -import java.lang.reflect.Method; -import java.text.ParseException; -import java.time.Instant; -import java.time.format.DateTimeFormatter; -import org.apache.zest.api.ZestAPI; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.api.value.ValueComposite; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; -import org.json.JSONObject; -import org.json.JSONTokener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * ApplicationEvent player - */ -@Mixins(ApplicationEventPlayerService.Mixin.class) -public interface ApplicationEventPlayerService - extends ApplicationEventPlayer, ServiceComposite -{ - class Mixin - implements ApplicationEventPlayer - { - final Logger logger = LoggerFactory.getLogger( ApplicationEventPlayer.class ); - @Structure - UnitOfWorkFactory uowf; - - @Structure - Module module; - - @Structure - ZestAPI api; - - DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern( "EEE MMM dd HH:mm:ss zzz yyyy" ); - - @Override - public void playEvent( ApplicationEvent applicationEvent, Object object ) - throws ApplicationEventReplayException - { - UnitOfWork uow = uowf.currentUnitOfWork(); - Class handlerType = object.getClass(); - - // Get method - Method eventMethod = getEventMethod( handlerType, applicationEvent.name().get() ); - - if (eventMethod == null) - { - logger.warn( "Could not find event method " + applicationEvent.name().get() + " in entity of type " + handlerType.getName() ); - return; - } - - // Build parameters - try - { - String jsonParameters = applicationEvent.parameters().get(); - JSONObject parameters = (JSONObject) new JSONTokener( jsonParameters ).nextValue(); - Object[] args = new Object[eventMethod.getParameterTypes().length]; - for (int i = 1; i < eventMethod.getParameterTypes().length; i++) - { - Class parameterType = eventMethod.getParameterTypes()[i]; - - String paramName = "param" + i; - - Object value = parameters.get( paramName ); - - args[i] = getParameterArgument( parameterType, value, uow ); - } - - args[0] = applicationEvent; - - // Invoke method - logger.debug( "Replay:" + applicationEvent + " on:" + object ); - - eventMethod.invoke( object, args ); - } catch (Exception e) - { - throw new ApplicationEventReplayException( applicationEvent, e ); - } - } - - private Object getParameterArgument( Class parameterType, Object value, UnitOfWork uow ) throws ParseException - { - if (value.equals( JSONObject.NULL )) - return null; - - if (parameterType.equals( String.class )) - { - return (String) value; - } else if (parameterType.equals( Boolean.class ) || parameterType.equals( Boolean.TYPE )) - { - return (Boolean) value; - } else if (parameterType.equals( Long.class ) || parameterType.equals( Long.TYPE )) - { - return ((Number) value).longValue(); - } else if (parameterType.equals( Integer.class ) || parameterType.equals( Integer.TYPE )) - { - return ((Number) value).intValue(); - } else if (parameterType.equals( Instant.class )) - { - return dateFormat.parse( (String) value ); - } else if (ValueComposite.class.isAssignableFrom( parameterType )) - { - return module.newValueFromSerializedState( parameterType, (String) value ); - } else if (parameterType.isInterface()) - { - return uow.get( parameterType, (String) value ); - } else if (parameterType.isEnum()) - { - return Enum.valueOf( (Class) parameterType, value.toString() ); - } else - { - throw new IllegalArgumentException( "Unknown parameter type:" + parameterType.getName() ); - } - } - - private Method getEventMethod( Class aClass, String eventName ) - { - for (Method method : aClass.getMethods()) - { - if (method.getName().equals( eventName )) - { - Class[] parameterTypes = method.getParameterTypes(); - if (parameterTypes.length > 0 && parameterTypes[0].equals( ApplicationEvent.class )) - return method; - } - } - return null; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventReplayException.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventReplayException.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventReplayException.java deleted file mode 100644 index 0eafa14..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/ApplicationEventReplayException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.replay; - -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; - -/** - * An event replay failed. - */ -public class ApplicationEventReplayException - extends RuntimeException -{ - private ApplicationEvent event; - - public ApplicationEventReplayException( ApplicationEvent event, Throwable cause ) - { - super( cause ); - this.event = event; - } - - @Override - public String getMessage() - { - return "Could not replay event:" + event + ", caused by:" + getCause(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/package.html deleted file mode 100644 index d8f137e..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/replay/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing Application Replay.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/AbstractApplicationEventStoreMixin.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/AbstractApplicationEventStoreMixin.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/AbstractApplicationEventStoreMixin.java deleted file mode 100644 index c25bb5d..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/AbstractApplicationEventStoreMixin.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; -import org.apache.zest.api.entity.Identity; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.structure.ModuleDescriptor; -import org.apache.zest.api.type.ValueType; -import org.apache.zest.api.value.ValueBuilder; -import org.apache.zest.api.value.ValueBuilderFactory; -import org.apache.zest.functional.Iterables; -import org.apache.zest.io.Input; -import org.apache.zest.io.Inputs; -import org.apache.zest.io.Output; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static java.util.Collections.synchronizedList; - -/** - * Base implementation for ApplicationEventStores. - */ -public abstract class AbstractApplicationEventStoreMixin - implements ApplicationEventStore, ApplicationEventStream, ApplicationEventStoreActivation -{ - @This - protected Identity identity; - - protected Logger logger; - protected ValueType domainEventType; - protected ValueType transactionEventsType; - - protected Lock lock = new ReentrantLock(); - - @Structure - protected ModuleDescriptor module; - - @Structure - private ValueBuilderFactory vbf; - - private ExecutorService transactionNotifier; - - final private List> listeners = synchronizedList( new ArrayList>() ); - - private long lastTimestamp = 0; - - @Override - public void activateApplicationEventStore() - throws Exception - { - logger = LoggerFactory.getLogger( identity.identity().get() ); - - domainEventType = module.valueDescriptor( ApplicationEvent.class.getName() ).valueType(); - transactionEventsType = module.valueDescriptor( TransactionApplicationEvents.class.getName() ).valueType(); - - transactionNotifier = Executors.newSingleThreadExecutor(); - } - - @Override - public void passivateApplicationEventStore() - throws Exception - { - transactionNotifier.shutdown(); - transactionNotifier.awaitTermination( 10000, TimeUnit.MILLISECONDS ); - } - - // This is how transactions are put into the store - @Override - public TransactionApplicationEvents storeEvents( Iterable events ) throws IOException - { - // Create new TransactionApplicationEvents - ValueBuilder builder = vbf.newValueBuilder( TransactionApplicationEvents.class ); - Iterables.addAll( builder.prototype().events().get(), events ); - builder.prototype().timestamp().set( getCurrentTimestamp() ); - - final TransactionApplicationEvents transactionDomain = builder.newInstance(); - - // Lock store so noone else can interrupt - lock(); - try - { - storeEvents( transactionDomain ); - } finally - { - lock.unlock(); - } - - // Notify listeners - transactionNotifier.submit( new Runnable() - { - @Override - public void run() - { - synchronized (listeners) - { - Input input = Inputs.iterable( Collections.singleton( transactionDomain ) ); - for (Output listener : listeners) - { - try - { - input.transferTo( listener ); - } catch (Throwable e) - { - logger.warn( "Could not notify event listener", e ); - } - } - } - } - } ); - - return transactionDomain; - } - - // EventStream implementation - - - @Override - public void registerListener( Output listener ) - { - listeners.add( listener ); - } - - - @Override - public void unregisterListener( Output listener ) - { - listeners.remove( listener ); - } - - abstract protected void rollback() - throws IOException; - - abstract protected void commit() - throws IOException; - - abstract protected void storeEvents( TransactionApplicationEvents transactionDomain ) - throws IOException; - - /** - * Fix for this bug: - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6822370 - */ - protected void lock() - { - while (true) - { - try - { - lock.tryLock( 1000, TimeUnit.MILLISECONDS ); - break; - } catch (InterruptedException e) - { - // Try again - } - } - } - - private synchronized long getCurrentTimestamp() - { - long timestamp = System.currentTimeMillis(); - if (timestamp <= lastTimestamp) - timestamp = lastTimestamp + 1; // Increase by one to ensure uniqueness - lastTimestamp = timestamp; - return timestamp; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventSource.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventSource.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventSource.java deleted file mode 100644 index 275dfa0..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventSource.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source; - -import java.io.IOException; -import org.apache.zest.io.Input; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; - -/** - * An ApplicationEventSource is a source of application events that can be pulled in chunks. Events are grouped in the transactions in which they were created. - */ -public interface ApplicationEventSource -{ - /** - * Get list of event transactions after the given timestamp. - *

- * If they are on the exact same timestamp, they will not be included. - *

- * The method uses the visitor pattern, so a visitor is sent in which is given each transaction, one at a time. - * - * @param afterTimestamp timestamp of transactions - * @param maxTransactions maximum transactions - * @return list of event transactions - */ - Input transactionsAfter( long afterTimestamp, long maxTransactions ); - - /** - * Get list of event transactions before the given timestamp. - *

- * If they are on the exact same timestamp, they will not be included. - *

- * The method uses the visitor pattern, so a visitor is sent in which is given each transaction, one at a time. - *

- * The transactions are sent to the visitor with the latest transaction first, i.e. walking backwards in the stream. - * - * @param beforeTimestamp timestamp of transactions - * @param maxTransactions maximum transactions - * @return list of event transactions - */ - Input transactionsBefore( long beforeTimestamp, long maxTransactions ); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStore.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStore.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStore.java deleted file mode 100644 index 3b74ac3..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStore.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source; - -import java.io.IOException; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; - -/** - * Store of application-events. - */ -public interface ApplicationEventStore -{ - TransactionApplicationEvents storeEvents( Iterable events ) throws IOException; -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStoreActivation.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStoreActivation.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStoreActivation.java deleted file mode 100644 index 7847a78..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStoreActivation.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source; - -import org.apache.zest.api.activation.ActivatorAdapter; -import org.apache.zest.api.service.ServiceReference; - -public interface ApplicationEventStoreActivation -{ - - void activateApplicationEventStore() - throws Exception; - - void passivateApplicationEventStore() - throws Exception; - - public static class Activator - extends ActivatorAdapter> - { - - @Override - public void afterActivation( ServiceReference activated ) - throws Exception - { - activated.get().activateApplicationEventStore(); - } - - @Override - public void beforePassivation( ServiceReference passivating ) - throws Exception - { - passivating.get().passivateApplicationEventStore(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStream.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStream.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStream.java deleted file mode 100644 index 0cd003d..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/ApplicationEventStream.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source; - -import org.apache.zest.io.Output; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; - -/** - * Stream of event transactions. Registering with a stream will - * allow the subscriber to get callbacks when new transactions - * are available. The callbacks are done asynchronously. - */ -public interface ApplicationEventStream -{ - void registerListener( Output listener ); - - void unregisterListener( Output listener ); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEventParameters.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEventParameters.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEventParameters.java deleted file mode 100644 index ad62582..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEventParameters.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source.helper; - -import org.json.JSONException; -import org.json.JSONObject; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; - -/** - * Utility class to pick out parameters by name or index as strings from a ApplicationEvent - */ -public class ApplicationEventParameters -{ - /** - * Get the named parameter from an event. - * - * @param event event with parameters - * @param name name of parameter - * @return the parameter with the given name or null - */ - public static String getParameter( ApplicationEvent event, String name ) - { - String parametersJson = event.parameters().get(); - try - { - JSONObject jsonObject = new JSONObject( parametersJson ); - return jsonObject.get( name ).toString(); - } catch (JSONException e) - { - return null; - } - } - - /** - * Get parameter with given index. - * - * @param event event with parameters - * @param idx index of parameter - * @return the parameter with the given index or null - */ - public static String getParameter( ApplicationEvent event, int idx ) - { - try - { - String parametersJson = event.parameters().get(); - JSONObject jsonObject = new JSONObject( parametersJson ); - return jsonObject.get( "param" + idx ).toString(); - } catch (JSONException e) - { - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEvents.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEvents.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEvents.java deleted file mode 100644 index edd5c8f..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationEvents.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source.helper; - -import java.lang.reflect.Method; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; -import org.apache.zest.api.util.Methods; -import org.apache.zest.functional.Iterables; -import org.apache.zest.io.Output; -import org.apache.zest.io.Receiver; -import org.apache.zest.io.Sender; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; -import org.apache.zest.library.eventsourcing.application.replay.ApplicationEventPlayer; -import org.apache.zest.library.eventsourcing.application.replay.ApplicationEventReplayException; - -/** - * Helper methods for working with Iterables of DomainEvents and UnitOfWorkDomainEventsValue. - */ -public class ApplicationEvents -{ - public static Iterable events( Iterable transactions ) - { - List> events = new ArrayList<>(); - for (TransactionApplicationEvents transactionDomain : transactions) - { - events.add( transactionDomain.events().get() ); - } - - Iterable[] iterables = (Iterable[]) new Iterable[events.size()]; - return Iterables.flatten( events.toArray( iterables ) ); - } - - public static Iterable events( TransactionApplicationEvents... transactionDomains ) - { - List> events = new ArrayList>(); - for (TransactionApplicationEvents transactionDomain : transactionDomains) - { - events.add( transactionDomain.events().get() ); - } - - Iterable[] iterables = (Iterable[]) new Iterable[events.size()]; - return Iterables.flatten( events.>toArray( iterables ) ); - } - - public static boolean matches( Predicate specification, Iterable transactions ) - { - return Iterables.filter( specification, events( transactions ) ).iterator().hasNext(); - } - - // Common specifications - -// public static Predicate withNames( final Iterable names ) -// { -// return new Predicate() -// { -// @Override -// public boolean test( ApplicationEvent event ) -// { -// for (String name : names) -// { -// if (event.name().get().equals( name )) -// return true; -// } -// return false; -// } -// }; -// } -// -// public static Predicate withNames( final String... names ) -// { -// return new Predicate() -// { -// @Override -// public boolean test( ApplicationEvent event ) -// { -// for (String name : names) -// { -// if (event.name().get().equals( name )) -// return true; -// } -// return false; -// } -// }; -// } -// - public static Predicate withNames( final Class eventClass ) - { - return new WithNamesPredicate(eventClass ); - -// ApplicationEvents.withNames( Iterables.map( new Function() -// { -// @Override -// public String apply( Method method ) -// { -// return method.getName(); -// } -// }, Iterables.toList( Methods.METHODS_OF.apply( eventClass ) ) )); - } - - public static Predicate afterDate( final Instant afterDate ) - { - return event -> event.on().get().isAfter( afterDate ); - } - - public static Predicate beforeDate( final Instant beforeDate ) - { - return event -> event.on().get().isBefore( beforeDate ); - } - - public static Predicate withUsecases( final String... names ) - { - return event -> { - for (String name : names) - { - if (event.usecase().get().equals( name )) - return true; - } - return false; - }; - } - - public static Predicate paramIs( final String name, final String value ) - { - return event -> ApplicationEventParameters.getParameter( event, name ).equals( value ); - } - - public static Output playEvents( final ApplicationEventPlayer player, final Object eventHandler ) - { - final Predicate specification = ApplicationEvents.withNames( eventHandler.getClass() ); - - return new Output() - { - @Override - public void receiveFrom(Sender sender) throws ApplicationEventReplayException, SenderThrowableType - { - sender.sendTo( new Receiver() - { - @Override - public void receive( TransactionApplicationEvents item ) throws ApplicationEventReplayException - { - for (ApplicationEvent applicationEvent : events( item )) - { - if (specification.test( applicationEvent )) - player.playEvent( applicationEvent, eventHandler ); - } - } - } ); - } - }; - } - - private static class WithNamesPredicate implements Predicate - { - private final Class eventClass; - - public WithNamesPredicate( Class eventClass ) - { - this.eventClass = eventClass; - } - - @Override - public boolean test( ApplicationEvent event ) - { - return Methods.METHODS_OF.apply( eventClass ) - .map( Method::getName ) - .anyMatch( name -> event.name().get().equals( name ) ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationTransactionTracker.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationTransactionTracker.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationTransactionTracker.java deleted file mode 100644 index 112a62a..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/ApplicationTransactionTracker.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source.helper; - -import org.apache.zest.api.configuration.Configuration; -import org.apache.zest.io.Output; -import org.apache.zest.io.Receiver; -import org.apache.zest.io.Sender; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; -import org.apache.zest.library.eventsourcing.application.source.ApplicationEventSource; -import org.apache.zest.library.eventsourcing.application.source.ApplicationEventStream; -import org.apache.zest.library.eventsourcing.domain.source.helper.DomainEventTrackerConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Helper that enables a service to easily track transactions. - *

- * Upon startup the tracker will get all the transactions from the store since the last - * check, and delegate them to the given Output. It will also register itself - * with the store so that it can get continuous updates. - *

- *

- * Then, as transactions come in from the store, they will be processed in real-time. - * If a transaction is successfully handled the configuration of the service, which must - * extend DomainEventTrackerConfiguration, will update the marker for the last successfully handled transaction. - *

- */ -public class ApplicationTransactionTracker -{ - private Configuration configuration; - private Output output; - private ApplicationEventStream stream; - private ApplicationEventSource source; - private boolean started = false; - private boolean upToSpeed = false; - private Logger logger; - private Output trackerOutput; - - public ApplicationTransactionTracker( ApplicationEventStream stream, ApplicationEventSource source, - Configuration configuration, - Output output ) - { - this.stream = stream; - this.configuration = configuration; - this.source = source; - this.output = output; - - logger = LoggerFactory.getLogger( output.getClass() ); - } - - public void start() - { - if (!started) - { - started = true; - - // Get events since last check - upToSpeed = true; // Pretend that we are up to speed from now on - trackerOutput = output(); - try - { - source.transactionsAfter( configuration.get().lastOffset().get(), Long.MAX_VALUE ).transferTo( trackerOutput ); - } catch (Throwable receiverThrowableType) - { - upToSpeed = false; - } - - stream.registerListener( trackerOutput ); - } - } - - public void stop() - { - if (started) - { - started = false; - stream.unregisterListener( trackerOutput ); - upToSpeed = false; - } - } - - private Output output() - { - return new Output() - { - @Override - public void receiveFrom(final Sender sender) throws ReceiverThrowableType, SenderThrowableType - { - if (!upToSpeed) - { - // The tracker has not handled successfully all transactions before, - // so it needs to get the backlog first - - upToSpeed = true; // Pretend that we are up to speed from now on - - // Get all transactions from last timestamp, including the one in this call - try - { - source.transactionsAfter( configuration.get().lastOffset().get(), Long.MAX_VALUE ).transferTo( trackerOutput ); - } catch (Throwable e) - { - upToSpeed = false; - throw (SenderThrowableType) e; - } - } - - try - { - output.receiveFrom( new Sender() - { - @Override - public void sendTo(final Receiver receiver) throws ReceiverThrowableType, SenderThrowableType - { - sender.sendTo( new Receiver() - { - @Override - public void receive( TransactionApplicationEvents item ) throws ReceiverThrowableType - { - receiver.receive( item ); - - // Events in this transactionDomain were handled successfully so store new marker - configuration.get().lastOffset().set( item.timestamp().get() ); - configuration.save(); - } - } ); - } - } ); - } catch (Throwable receiverThrowableType) - { - upToSpeed = false; - throw (ReceiverThrowableType) receiverThrowableType; - } - } - }; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/package.html deleted file mode 100644 index 931b401..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/helper/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing Application Source Helpers.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/MemoryApplicationEventStoreService.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/MemoryApplicationEventStoreService.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/MemoryApplicationEventStoreService.java deleted file mode 100644 index cde4af5..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/MemoryApplicationEventStoreService.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.zest.library.eventsourcing.application.source.memory; - -import org.apache.zest.api.activation.Activators; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.service.ServiceComposite; -import org.apache.zest.io.Input; -import org.apache.zest.io.Output; -import org.apache.zest.io.Receiver; -import org.apache.zest.io.Sender; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; -import org.apache.zest.library.eventsourcing.application.source.*; - -import java.io.IOException; -import java.util.*; - -/** - * In-Memory ApplicationEventStore. Mainly used for testing. - */ -@Mixins( MemoryApplicationEventStoreService.MemoryStoreMixin.class ) -@Activators( ApplicationEventStoreActivation.Activator.class ) -public interface MemoryApplicationEventStoreService - extends ApplicationEventSource, ApplicationEventStore, ApplicationEventStream, ApplicationEventStoreActivation, ServiceComposite -{ - abstract class MemoryStoreMixin - extends AbstractApplicationEventStoreMixin - implements ApplicationEventSource, ApplicationEventStoreActivation - { - // This list holds all transactions - private LinkedList store = new LinkedList(); - - @Override - public Input transactionsAfter( final long afterTimestamp, final long maxTransactions ) - { - return new Input() - { - @Override - public void transferTo( Output output ) - throws IOException, ReceiverThrowableType - { - // Lock store first - lock.lock(); - try - { - output.receiveFrom( new Sender() - { - @Override - public void sendTo( Receiver receiver ) - throws ReceiverThrowableType, IOException - { - Iterator iterator = store.iterator(); - - long count = 0; - - while( iterator.hasNext() && count < maxTransactions ) - { - TransactionApplicationEvents next = iterator.next(); - if( next.timestamp().get() > afterTimestamp ) - { - receiver.receive( next ); - count++; - } - } - } - }); - } - finally - { - lock.unlock(); - } - } - }; - } - - @Override - public Input transactionsBefore( final long beforeTimestamp, final long maxTransactions ) - { - return new Input() - { - @Override - public void transferTo( Output output ) - throws IOException, ReceiverThrowableType - { - // Lock store first - lock.lock(); - try - { - output.receiveFrom( new Sender() - { - @Override - public void sendTo( Receiver receiver ) - throws ReceiverThrowableType, IOException - { - Iterator iterator = store.descendingIterator(); - - long count = 0; - - while( iterator.hasNext() && count < maxTransactions ) - { - TransactionApplicationEvents next = iterator.next(); - if( next.timestamp().get() < beforeTimestamp ) - { - receiver.receive( next ); - count++; - } - } - } - }); - } - finally - { - lock.unlock(); - } - } - }; - } - - @Override - protected void storeEvents( TransactionApplicationEvents transactionDomain ) throws IOException - { - store.add( transactionDomain ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/package.html deleted file mode 100644 index 0b74afe..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/memory/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing in-memory EventStore.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/package.html deleted file mode 100644 index 6ac248d..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/application/source/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing Application Source.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/EventsourcingAssembler.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/EventsourcingAssembler.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/EventsourcingAssembler.java deleted file mode 100644 index 7976d4b..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/EventsourcingAssembler.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.zest.library.eventsourcing.bootstrap; - -import org.apache.zest.bootstrap.Assemblers; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ImportedServiceDeclaration; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.library.eventsourcing.application.api.ApplicationEvent; -import org.apache.zest.library.eventsourcing.application.api.TransactionApplicationEvents; -import org.apache.zest.library.eventsourcing.application.factory.ApplicationEventFactoryService; -import org.apache.zest.library.eventsourcing.domain.api.DomainEventValue; -import org.apache.zest.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue; -import org.apache.zest.library.eventsourcing.domain.factory.CurrentUserUoWPrincipal; -import org.apache.zest.library.eventsourcing.domain.factory.DomainEventFactoryService; - -public class EventsourcingAssembler - extends Assemblers.Visibility -{ - private boolean domainEvents; - private boolean applicationEvents; - - private boolean uowPrincipal; - - public EventsourcingAssembler withDomainEvents() - { - domainEvents = true; - return this; - } - - public EventsourcingAssembler withApplicationEvents() - { - applicationEvents = true; - return this; - } - - public EventsourcingAssembler withCurrentUserFromUOWPrincipal() - { - uowPrincipal = true; - return this; - } - - @Override - public void assemble(ModuleAssembly module) throws AssemblyException - { - if( domainEvents ) - { - module.values( DomainEventValue.class, UnitOfWorkDomainEventsValue.class ); - module.services( DomainEventFactoryService.class).visibleIn(visibility() ); - } - - if( applicationEvents ) - { - module.values( ApplicationEvent.class, TransactionApplicationEvents.class ); - module.services( ApplicationEventFactoryService.class ).visibleIn( visibility() ); - } - - if( uowPrincipal ) - { - module.importedServices( CurrentUserUoWPrincipal.class ) - .importedBy( ImportedServiceDeclaration.NEW_OBJECT ); - module.objects( CurrentUserUoWPrincipal.class ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/package.html deleted file mode 100644 index 89a0dce..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/bootstrap/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing Assembly.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvent.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvent.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvent.java deleted file mode 100644 index d6813f8..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.zest.library.eventsourcing.domain.api; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Annotate methods that should trigger domain events with this annotation. Example: - *
- * @DomainEvent
- * void changedDescription(String newDescription);
- * 
- * Event methods may only change state. They may not fail or thrown exceptions. The name of the - * method should be in past tense, as in something HAS already occurred, and the method is merely - * reacting to it. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -public @interface DomainEvent -{ -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEventValue.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEventValue.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEventValue.java deleted file mode 100644 index 9f52ae1..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEventValue.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.zest.library.eventsourcing.domain.api; - -import org.apache.zest.api.property.Property; -import org.apache.zest.api.value.ValueComposite; - -/** - * Representation of a domain-event. - *

An event is triggered by calling a method that is of the form: - *

- *

- * @DomainEvent
- * void someName(SomeParam param, AnotherParam param2);
- * 
- * - */ -public interface DomainEventValue - extends ValueComposite -{ - // Type of the entity being invoked - Property entityType(); - - // Id of the entity that generated the event - Property entityId(); - - // Name of method/event - Property name(); - - // Method parameters as JSON - Property parameters(); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvents.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvents.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvents.java deleted file mode 100644 index 14af4c6..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/DomainEvents.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.zest.library.eventsourcing.domain.api; - -/** - * This gives access to the current domain event. This is only usable within methods - * marked with @DomainEvent annotation. - */ -public class DomainEvents -{ - private static ThreadLocal event = new ThreadLocal(); - - public static DomainEventValue currentEvent() - { - return event.get(); - } - - /** - * This is called by the EventSourcing library, either during creation or replay. - * Don't use in application code. - * - * @param currentEvent new current event - */ - public static void setCurrentEvent(DomainEventValue currentEvent) - { - event.set( currentEvent ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/UnitOfWorkDomainEventsValue.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/UnitOfWorkDomainEventsValue.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/UnitOfWorkDomainEventsValue.java deleted file mode 100644 index 4cec265..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/UnitOfWorkDomainEventsValue.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.zest.library.eventsourcing.domain.api; - -import java.time.Instant; -import java.util.List; -import org.apache.zest.api.common.Optional; -import org.apache.zest.api.common.UseDefaults; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.value.ValueComposite; - -/** - * List of events for a single UnitOfWork. Events must always be consumed - * in UoW units, in order to ensure that the result is consistent - * with what happened in that UoW. - * - * Context that is common to all events in the UoW is stored here rather than - * in the individual event. - */ -public interface UnitOfWorkDomainEventsValue - extends ValueComposite -{ - // Version of the application that created these events - Property version(); - - // Usecase name - Property usecase(); - - // When the event occurred - Property timestamp(); - - // Who performed the event. Taken from CurrentUser service. - @Optional - Property user(); - - // List of events for this transaction - @UseDefaults - Property> events(); -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/package.html ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/package.html b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/package.html deleted file mode 100644 index f54ea77..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/api/package.html +++ /dev/null @@ -1,24 +0,0 @@ - - - -

EventSourcing Domain API.

- - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserSubject.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserSubject.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserSubject.java deleted file mode 100644 index a35dbf9..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserSubject.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.zest.library.eventsourcing.domain.factory; - -import java.security.AccessController; -import javax.security.auth.Subject; -import org.apache.zest.library.eventsourcing.domain.spi.CurrentUser; - -/** - * Uses thread-associated Subject to get the current user name. Default to "unknown". - */ -public class CurrentUserSubject - implements CurrentUser -{ - @Override - public String getCurrentUser() - { - try - { - return Subject.getSubject( AccessController.getContext() ).getPrincipals().iterator().next().getName(); - } catch (Exception e) - { - return "unknown"; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/d9569cd6/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserUoWPrincipal.java ---------------------------------------------------------------------- diff --git a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserUoWPrincipal.java b/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserUoWPrincipal.java deleted file mode 100644 index a21a626..0000000 --- a/libraries/eventsourcing/src/main/java/org/apache/zest/library/eventsourcing/domain/factory/CurrentUserUoWPrincipal.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.zest.library.eventsourcing.domain.factory; - -import java.security.Principal; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.library.eventsourcing.domain.spi.CurrentUser; - -/** - * CurrentUser implementation that gets a Principal object from the meta-info of the current UnitOfWork. Default to "unknown". - */ -public class CurrentUserUoWPrincipal - implements CurrentUser -{ - @Structure - private UnitOfWorkFactory uowf; - - @Override - public String getCurrentUser() - { - try - { - return uowf.currentUnitOfWork().metaInfo( Principal.class ).getName(); - } catch (Exception e) - { - return "unknown"; - } - } -}