Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 341E617544 for ; Tue, 21 Apr 2015 11:50:14 +0000 (UTC) Received: (qmail 5214 invoked by uid 500); 21 Apr 2015 11:50:14 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 5149 invoked by uid 500); 21 Apr 2015 11:50:14 -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 5089 invoked by uid 99); 21 Apr 2015 11:50:14 -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; Tue, 21 Apr 2015 11:50:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DC121E0D5B; Tue, 21 Apr 2015 11:50:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: paulmerlin@apache.org To: commits@zest.apache.org Date: Tue, 21 Apr 2015 11:50:15 -0000 Message-Id: In-Reply-To: <44c1d215a4984039ac56399268ee67b0@git.apache.org> References: <44c1d215a4984039ac56399268ee67b0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/18] zest-sandbox git commit: Move Qi4j related projects in a `qi4j/` subfolder http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObservableMixin.java.svn-base ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObservableMixin.java.svn-base b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObservableMixin.java.svn-base new file mode 100644 index 0000000..c95c7ae --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObservableMixin.java.svn-base @@ -0,0 +1,64 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.property.Property; + +public class ExceptionObservableMixin + implements ExceptionObservable +{ + @This private Property observer; + + public void addExceptionObserver( ExceptionObserver observer ) + { + synchronized( this ) + { + ExceptionObserver existing = this.observer.get(); + if( existing == null ) + { + this.observer.set( observer ); + return; + } + this.observer.set( new DelegatingExceptionObserver( existing ) ); + } + } + + public void removeExceptionObserver( ExceptionObserver observer ) + { + synchronized( this ) + { + ExceptionObserver current = this.observer.get(); + if( current == null ) + { + return; + } + if( current == observer ) + { + this.observer.set( null ); + return; + } + if( current instanceof DelegatingExceptionObserver ) + { + DelegatingExceptionObserver delegator = (DelegatingExceptionObserver) this.observer; + this.observer.set( delegator.removeExceptionObserver( observer )); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObserver.java.svn-base ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObserver.java.svn-base b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObserver.java.svn-base new file mode 100644 index 0000000..1155a3e --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ExceptionObserver.java.svn-base @@ -0,0 +1,23 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public interface ExceptionObserver +{ + void notify( String message, Object source, Throwable exception ); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/NullExceptionHandling.java.svn-base ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/NullExceptionHandling.java.svn-base b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/NullExceptionHandling.java.svn-base new file mode 100644 index 0000000..ff55d1f --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/NullExceptionHandling.java.svn-base @@ -0,0 +1,27 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public class NullExceptionHandling + implements ExceptionHandling +{ + public void exceptionOccurred( String message, Object location, Throwable exception ) + { + // Do Nothing! + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ObservableExceptionHandlingService.java.svn-base ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ObservableExceptionHandlingService.java.svn-base b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ObservableExceptionHandlingService.java.svn-base new file mode 100644 index 0000000..359ff84 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/ObservableExceptionHandlingService.java.svn-base @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.concern.Concerns; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.service.ServiceComposite; + + +@Concerns( { ExceptionHandlingNotificationConcern.class } ) +@Mixins( { ExceptionObservableMixin.class, NullExceptionHandling.class } ) +public interface ObservableExceptionHandlingService extends ExceptionHandling, ExceptionObservable, ServiceComposite +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SimpleExceptionHandlingService.java.svn-base ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SimpleExceptionHandlingService.java.svn-base b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SimpleExceptionHandlingService.java.svn-base new file mode 100644 index 0000000..9054cbe --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SimpleExceptionHandlingService.java.svn-base @@ -0,0 +1,26 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.service.ServiceComposite; +import org.qi4j.api.mixin.Mixins; + +@Mixins( SystemErrExceptionHandlingMixin.class ) +public interface SimpleExceptionHandlingService extends ExceptionHandling, ServiceComposite +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SystemErrExceptionHandlingMixin.java.svn-base ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SystemErrExceptionHandlingMixin.java.svn-base b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SystemErrExceptionHandlingMixin.java.svn-base new file mode 100644 index 0000000..20d9b74 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/.svn/text-base/SystemErrExceptionHandlingMixin.java.svn-base @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public class SystemErrExceptionHandlingMixin + implements ExceptionHandling +{ + public void exceptionOccurred( String message, Object location, Throwable exception ) + { + System.err.print( location + " " ); + System.err.println( message ); + exception.printStackTrace( System.err ); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/DelegatingExceptionObserver.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/DelegatingExceptionObserver.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/DelegatingExceptionObserver.java new file mode 100644 index 0000000..903b5d6 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/DelegatingExceptionObserver.java @@ -0,0 +1,85 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import java.util.Iterator; +import java.util.LinkedList; + +public class DelegatingExceptionObserver + implements ExceptionObserver +{ + private LinkedList observers; + + public DelegatingExceptionObserver( ExceptionObserver existing ) + { + observers = new LinkedList(); + observers.add( existing ); + } + + public void notify( String message, Object source, Throwable exception ) + { + Iterator iterator; + synchronized( this ) + { + iterator = observers.iterator(); + } + while( iterator.hasNext() ) + { + ExceptionObserver observer = iterator.next(); + try + { + observer.notify( message, source, exception ); + } + catch( Throwable e ) + { + System.err.println( "WARNING: ExceptionObserver " + observer + " threw an exception. See below." ); + e.printStackTrace( System.err ); + } + } + } + + void addExceptionObserver( ExceptionObserver observer ) + { + synchronized( this ) + { + LinkedList clone = new LinkedList(); + clone.addAll( observers ); + clone.add( observer ); + observers = clone; + } + } + + ExceptionObserver removeExceptionObserver( ExceptionObserver observer ) + { + synchronized( this ) + { + LinkedList clone = new LinkedList(); + clone.addAll( observers ); + clone.remove( observer ); + if( observers.size() == 1 ) + { + ExceptionObserver last = observers.removeFirst(); + observers = null; + return last; + } + observers = clone; + return this; + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandling.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandling.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandling.java new file mode 100644 index 0000000..016e8cd --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandling.java @@ -0,0 +1,23 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public interface ExceptionHandling +{ + void exceptionOccurred( String message, Object location, Throwable exception ); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandlingNotificationConcern.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandlingNotificationConcern.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandlingNotificationConcern.java new file mode 100644 index 0000000..d0f22ee --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionHandlingNotificationConcern.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.concern.ConcernOf; +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.property.Property; + +@Mixins( ExceptionObservableMixin.class ) +public class ExceptionHandlingNotificationConcern extends ConcernOf + implements ExceptionHandling +{ + @This private Property observer; + + public void exceptionOccurred( String message, Object location, Throwable exception ) + { + ExceptionObserver current; + synchronized( this ) + { + current = observer.get(); + } + current.notify( message, location, exception ); + next.exceptionOccurred( message, location, exception ); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservable.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservable.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservable.java new file mode 100644 index 0000000..7009895 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservable.java @@ -0,0 +1,25 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public interface ExceptionObservable +{ + void addExceptionObserver( ExceptionObserver observer ); + + void removeExceptionObserver( ExceptionObserver observer ); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservableMixin.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservableMixin.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservableMixin.java new file mode 100644 index 0000000..f08e092 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObservableMixin.java @@ -0,0 +1,64 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.property.Property; + +public class ExceptionObservableMixin + implements ExceptionObservable +{ + @This private Property observer; + + public void addExceptionObserver( ExceptionObserver observer ) + { + synchronized( this ) + { + ExceptionObserver existing = this.observer.get(); + if( existing == null ) + { + this.observer.set( observer ); + return; + } + this.observer.set( new DelegatingExceptionObserver( existing ) ); + } + } + + public void removeExceptionObserver( ExceptionObserver observer ) + { + synchronized( this ) + { + ExceptionObserver current = this.observer.get(); + if( current == null ) + { + return; + } + if( current == observer ) + { + this.observer.set( null ); + return; + } + if( current instanceof DelegatingExceptionObserver ) + { + DelegatingExceptionObserver delegator = (DelegatingExceptionObserver) this.observer; + this.observer.set( delegator.removeExceptionObserver( observer ) ); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObserver.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObserver.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObserver.java new file mode 100644 index 0000000..1155a3e --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ExceptionObserver.java @@ -0,0 +1,23 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public interface ExceptionObserver +{ + void notify( String message, Object source, Throwable exception ); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/NullExceptionHandling.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/NullExceptionHandling.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/NullExceptionHandling.java new file mode 100644 index 0000000..ff55d1f --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/NullExceptionHandling.java @@ -0,0 +1,27 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public class NullExceptionHandling + implements ExceptionHandling +{ + public void exceptionOccurred( String message, Object location, Throwable exception ) + { + // Do Nothing! + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ObservableExceptionHandlingService.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ObservableExceptionHandlingService.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ObservableExceptionHandlingService.java new file mode 100644 index 0000000..359ff84 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/ObservableExceptionHandlingService.java @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.concern.Concerns; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.service.ServiceComposite; + + +@Concerns( { ExceptionHandlingNotificationConcern.class } ) +@Mixins( { ExceptionObservableMixin.class, NullExceptionHandling.class } ) +public interface ObservableExceptionHandlingService extends ExceptionHandling, ExceptionObservable, ServiceComposite +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SimpleExceptionHandlingService.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SimpleExceptionHandlingService.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SimpleExceptionHandlingService.java new file mode 100644 index 0000000..4c4177f --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SimpleExceptionHandlingService.java @@ -0,0 +1,26 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.service.ServiceComposite; + +@Mixins( SystemErrExceptionHandlingMixin.class ) +public interface SimpleExceptionHandlingService extends ExceptionHandling, ServiceComposite +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SystemErrExceptionHandlingMixin.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SystemErrExceptionHandlingMixin.java b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SystemErrExceptionHandlingMixin.java new file mode 100644 index 0000000..20d9b74 --- /dev/null +++ b/qi4j/libraries/exception/src/main/java/org/qi4j/library/exception/SystemErrExceptionHandlingMixin.java @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.exception; + +public class SystemErrExceptionHandlingMixin + implements ExceptionHandling +{ + public void exceptionOccurred( String message, Object location, Throwable exception ) + { + System.err.print( location + " " ); + System.err.println( message ); + exception.printStackTrace( System.err ); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/.svn/all-wcprops ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/.svn/all-wcprops b/qi4j/libraries/exception/src/test/.svn/all-wcprops new file mode 100644 index 0000000..3e44ac5 --- /dev/null +++ b/qi4j/libraries/exception/src/test/.svn/all-wcprops @@ -0,0 +1,5 @@ +K 25 +svn:wc:ra_dav:version-url +V 70 +/repos/ops4j/!svn/ver/12464/projects/qi4j/libraries/exception/src/test +END http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/.svn/entries ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/.svn/entries b/qi4j/libraries/exception/src/test/.svn/entries new file mode 100644 index 0000000..c0f2cd1 --- /dev/null +++ b/qi4j/libraries/exception/src/test/.svn/entries @@ -0,0 +1,31 @@ +8 + +dir +14719 +https://scm.ops4j.org/repos/ops4j/projects/qi4j/libraries/exception/src/test +https://scm.ops4j.org/repos/ops4j + + + +2008-07-30T03:59:42.341738Z +12464 +niclas@hedhman.org + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +9b982a3c-3ae5-0310-a4bc-d9a3335569bd + +java +dir + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/.svn/format ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/.svn/format b/qi4j/libraries/exception/src/test/.svn/format new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/.svn/format @@ -0,0 +1 @@ +8 http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/.svn/all-wcprops ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/.svn/all-wcprops b/qi4j/libraries/exception/src/test/java/.svn/all-wcprops new file mode 100644 index 0000000..93d8820 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/.svn/all-wcprops @@ -0,0 +1,5 @@ +K 25 +svn:wc:ra_dav:version-url +V 75 +/repos/ops4j/!svn/ver/12464/projects/qi4j/libraries/exception/src/test/java +END http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/.svn/entries ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/.svn/entries b/qi4j/libraries/exception/src/test/java/.svn/entries new file mode 100644 index 0000000..a1715d1 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/.svn/entries @@ -0,0 +1,31 @@ +8 + +dir +14719 +https://scm.ops4j.org/repos/ops4j/projects/qi4j/libraries/exception/src/test/java +https://scm.ops4j.org/repos/ops4j + + + +2008-07-30T03:59:42.341738Z +12464 +niclas@hedhman.org + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +9b982a3c-3ae5-0310-a4bc-d9a3335569bd + +org +dir + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/.svn/format ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/.svn/format b/qi4j/libraries/exception/src/test/java/.svn/format new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/.svn/format @@ -0,0 +1 @@ +8 http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/.svn/all-wcprops ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/.svn/all-wcprops b/qi4j/libraries/exception/src/test/java/org/.svn/all-wcprops new file mode 100644 index 0000000..22383d1 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/.svn/all-wcprops @@ -0,0 +1,5 @@ +K 25 +svn:wc:ra_dav:version-url +V 79 +/repos/ops4j/!svn/ver/12464/projects/qi4j/libraries/exception/src/test/java/org +END http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/.svn/entries ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/.svn/entries b/qi4j/libraries/exception/src/test/java/org/.svn/entries new file mode 100644 index 0000000..59776b7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/.svn/entries @@ -0,0 +1,31 @@ +8 + +dir +14719 +https://scm.ops4j.org/repos/ops4j/projects/qi4j/libraries/exception/src/test/java/org +https://scm.ops4j.org/repos/ops4j + + + +2008-07-30T03:59:42.341738Z +12464 +niclas@hedhman.org + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +9b982a3c-3ae5-0310-a4bc-d9a3335569bd + +qi4j +dir + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/.svn/format ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/.svn/format b/qi4j/libraries/exception/src/test/java/org/.svn/format new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/.svn/format @@ -0,0 +1 @@ +8 http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/all-wcprops ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/all-wcprops b/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/all-wcprops new file mode 100644 index 0000000..a9f4e3f --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/all-wcprops @@ -0,0 +1,5 @@ +K 25 +svn:wc:ra_dav:version-url +V 84 +/repos/ops4j/!svn/ver/12464/projects/qi4j/libraries/exception/src/test/java/org/qi4j +END http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/entries ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/entries b/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/entries new file mode 100644 index 0000000..cd88c05 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/entries @@ -0,0 +1,31 @@ +8 + +dir +14719 +https://scm.ops4j.org/repos/ops4j/projects/qi4j/libraries/exception/src/test/java/org/qi4j +https://scm.ops4j.org/repos/ops4j + + + +2008-07-30T03:59:42.341738Z +12464 +niclas@hedhman.org + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +9b982a3c-3ae5-0310-a4bc-d9a3335569bd + +library +dir + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/format ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/format b/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/format new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/.svn/format @@ -0,0 +1 @@ +8 http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/all-wcprops ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/all-wcprops b/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/all-wcprops new file mode 100644 index 0000000..5b731d1 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/all-wcprops @@ -0,0 +1,5 @@ +K 25 +svn:wc:ra_dav:version-url +V 92 +/repos/ops4j/!svn/ver/12464/projects/qi4j/libraries/exception/src/test/java/org/qi4j/library +END http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/entries ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/entries b/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/entries new file mode 100644 index 0000000..d2c471b --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/entries @@ -0,0 +1,31 @@ +8 + +dir +14719 +https://scm.ops4j.org/repos/ops4j/projects/qi4j/libraries/exception/src/test/java/org/qi4j/library +https://scm.ops4j.org/repos/ops4j + + + +2008-07-30T03:59:42.341738Z +12464 +niclas@hedhman.org + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +9b982a3c-3ae5-0310-a4bc-d9a3335569bd + +exception +dir + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/format ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/format b/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/format new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/library/.svn/format @@ -0,0 +1 @@ +8 http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/all-wcprops ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/all-wcprops b/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/all-wcprops new file mode 100644 index 0000000..3fc5e56 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/all-wcprops @@ -0,0 +1,5 @@ +K 25 +svn:wc:ra_dav:version-url +V 102 +/repos/ops4j/!svn/ver/12464/projects/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception +END http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/entries ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/entries b/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/entries new file mode 100644 index 0000000..a327aea --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/entries @@ -0,0 +1,28 @@ +8 + +dir +14719 +https://scm.ops4j.org/repos/ops4j/projects/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception +https://scm.ops4j.org/repos/ops4j + + + +2008-07-30T03:59:42.341738Z +12464 +niclas@hedhman.org + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +9b982a3c-3ae5-0310-a4bc-d9a3335569bd + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/format ---------------------------------------------------------------------- diff --git a/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/format b/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/format new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/qi4j/libraries/exception/src/test/java/org/qi4j/library/exception/.svn/format @@ -0,0 +1 @@ +8 http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/dev-status.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/dev-status.xml b/qi4j/libraries/executor/dev-status.xml new file mode 100644 index 0000000..0c93156 --- /dev/null +++ b/qi4j/libraries/executor/dev-status.xml @@ -0,0 +1,14 @@ + + + + early + + none + + some + + + + ALv2 + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/pom.xml b/qi4j/libraries/executor/pom.xml new file mode 100644 index 0000000..d720245 --- /dev/null +++ b/qi4j/libraries/executor/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + + org.qi4j.sandbox + qi4j-sandbox-libraries + 0-SNAPSHOT + + org.qi4j.library + org.qi4j.library.executor + Qi4j Library - Executor + + + + org.qi4j.core + org.qi4j.core.api + + + org.qi4j.core + org.qi4j.core.bootstrap + test + + + org.qi4j.core + org.qi4j.core.testsupport + test + + + org.qi4j.core + org.qi4j.core.runtime + test + + + junit + junit + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteService.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteService.java b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteService.java new file mode 100644 index 0000000..5e41afb --- /dev/null +++ b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteService.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008, Rickard Öberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.library.executor; + +import java.util.concurrent.Executor; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.service.ServiceActivation; + +/** + * JAVADOC + */ +@Mixins( ExecutorMixin.class ) +public interface ExecuteService + extends Executor, ServiceActivation +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteSideEffect.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteSideEffect.java b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteSideEffect.java new file mode 100644 index 0000000..069c1bb --- /dev/null +++ b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecuteSideEffect.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008, Rickard Öberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.library.executor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * JAVADOC + */ +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.METHOD } ) +public @interface ExecuteSideEffect +{ + Class value(); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorMixin.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorMixin.java b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorMixin.java new file mode 100644 index 0000000..61cca65 --- /dev/null +++ b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorMixin.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2008, Rickard Öberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.library.executor; + +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import org.qi4j.api.service.ServiceActivation; + +/** + * Delegate Runnable's to a ScheduledThreadPoolExecutor + */ +public class ExecutorMixin + implements Executor, ServiceActivation +{ + private ExecutorService service; + + public void activateService() throws Exception + { + service = new ScheduledThreadPoolExecutor( 10 ); + } + + public void passivateService() throws Exception + { + System.out.println( "Shutdown executors" ); + service.shutdown(); + } + + public void execute( Runnable runnable ) + { + service.execute( runnable ); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorSideEffect.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorSideEffect.java b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorSideEffect.java new file mode 100644 index 0000000..9f6be86 --- /dev/null +++ b/qi4j/libraries/executor/src/main/java/org/qi4j/library/executor/ExecutorSideEffect.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2008, Rickard Öberg. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.qi4j.library.executor; + +import org.qi4j.api.common.AppliesTo; +import org.qi4j.api.injection.scope.Invocation; +import org.qi4j.api.injection.scope.Service; +import org.qi4j.api.injection.scope.Structure; +import org.qi4j.api.sideeffect.GenericSideEffect; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.concurrent.Executor; +import org.qi4j.api.structure.Module; + +/** + * JAVADOC + */ +@AppliesTo( ExecuteSideEffect.class ) +public class ExecutorSideEffect extends GenericSideEffect +{ + @Structure Module module; + @Service Executor executor; + + @Invocation ExecuteSideEffect execute; + + @Override public Object invoke( final Object target, final Method method, final Object[] objects ) throws Throwable + { + executor.execute( new SideEffectRunnable( target, method, objects ) ); + + return super.invoke( target, method, objects ); + } + + private class SideEffectRunnable implements Runnable + { + private final Object target; + private final Method method; + private final Object[] objects; + + public SideEffectRunnable( Object target, Method method, Object[] objects ) + { + this.target = target; + this.method = method; + this.objects = objects; + } + + public void run() + { + try + { + try + { + Object executed = module.newObject( execute.value() ); + runSideEffect( executed ); + } + catch( InvocationTargetException e ) + { + throw e.getTargetException(); + } + } + catch( Throwable t ) + { + t.printStackTrace(); + } + } + + private void runSideEffect( Object executed ) + throws Throwable + { + if( executed instanceof InvocationHandler ) + { + InvocationHandler handler = (InvocationHandler) executed; + handler.invoke( target, method, objects ); + } + else + { + method.invoke( executed, objects ); + } + } + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/executor/src/test/java/org/qi4j/library/framework/executor/ExecuteSideEffectTest.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/executor/src/test/java/org/qi4j/library/framework/executor/ExecuteSideEffectTest.java b/qi4j/libraries/executor/src/test/java/org/qi4j/library/framework/executor/ExecuteSideEffectTest.java new file mode 100644 index 0000000..4e89593 --- /dev/null +++ b/qi4j/libraries/executor/src/test/java/org/qi4j/library/framework/executor/ExecuteSideEffectTest.java @@ -0,0 +1,75 @@ +package org.qi4j.library.framework.executor; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.CountDownLatch; +import static junit.framework.Assert.assertTrue; +import org.junit.Test; +import org.qi4j.api.composite.TransientComposite; +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.sideeffect.SideEffects; +import org.qi4j.bootstrap.AssemblyException; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.library.executor.ExecuteService; +import org.qi4j.library.executor.ExecuteSideEffect; +import org.qi4j.library.executor.ExecutorSideEffect; +import org.qi4j.test.AbstractQi4jTest; + +/** + * JAVADOC + */ +public class ExecuteSideEffectTest + extends AbstractQi4jTest +{ + private static final CountDownLatch latch = new CountDownLatch( 1 ); + + public void assemble( ModuleAssembly module ) throws AssemblyException + { + module.transients( TestComposite.class ); + module.objects( LogCall.class ); + module.services( ExecuteService.class ).instantiateOnStartup(); + } + + @Test + public void givenMethodWithAnnotationWhenCallThenExecuteSideEffect() + throws InterruptedException + { + TestComposite instance = module.newTransient( TestComposite.class ); + System.out.println( instance.doStuff() ); + latch.await(); + assertTrue( "doStuff sideeffect called", LogCall.methodsCalled.contains( "doStuff" ) ); + } + + @SideEffects( ExecutorSideEffect.class ) + @Mixins( TestMixin.class ) + public interface TestComposite + extends TransientComposite + { + @ExecuteSideEffect( LogCall.class ) String doStuff(); + } + + public static abstract class TestMixin + implements TestComposite + { + public String doStuff() + { + return "Foo"; + } + } + + public static class LogCall + implements InvocationHandler + { + static Collection methodsCalled = new ArrayList(); + + public Object invoke( Object o, Method method, Object[] objects ) throws Throwable + { + methodsCalled.add( method.getName() ); + System.out.println( "method = " + method ); + latch.countDown(); + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/client/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/client/pom.xml b/qi4j/libraries/ldap/client/pom.xml new file mode 100644 index 0000000..da660d6 --- /dev/null +++ b/qi4j/libraries/ldap/client/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + + org.qi4j.library + org.qi4j.library.ldap + 0-SNAPSHOT + + org.qi4j.library + org.qi4j.library.ldap-client + Qi4j Library - LDAP Client + + + + org.qi4j.core + org.qi4j.core.api + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/pom.xml b/qi4j/libraries/ldap/pom.xml new file mode 100644 index 0000000..c309da0 --- /dev/null +++ b/qi4j/libraries/ldap/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + + org.qi4j.sandbox + qi4j-sandbox-libraries + 0-SNAPSHOT + + org.qi4j.library + org.qi4j.library.ldap + Qi4j Library - LDAP - Build POM + pom + + + client + server + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/pom.xml b/qi4j/libraries/ldap/server/pom.xml new file mode 100644 index 0000000..43313d1 --- /dev/null +++ b/qi4j/libraries/ldap/server/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + org.qi4j.library + org.qi4j.library.ldap + 0-SNAPSHOT + + org.qi4j.library + org.qi4j.library.ldap-server + Qi4j Library - LDAP Server + + + + org.qi4j.core + org.qi4j.core.api + + + org.apache.directory.server + apacheds-all + 1.5.4 + + + org.qi4j.core + org.qi4j.core.runtime + test + + + org.qi4j.core + org.qi4j.core.testsupport + test + + + org.slf4j + slf4j-simple + 1.4.2 + test + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/ApacheDirectoryServiceMixin.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/ApacheDirectoryServiceMixin.java b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/ApacheDirectoryServiceMixin.java new file mode 100644 index 0000000..d8b959f --- /dev/null +++ b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/ApacheDirectoryServiceMixin.java @@ -0,0 +1,142 @@ +/* + * Copyright 2009 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.ldap.server; + +import java.util.HashSet; +import java.util.Set; +import org.apache.directory.server.core.DefaultDirectoryService; +import org.apache.directory.server.core.DirectoryService; +import org.apache.directory.server.core.entry.ServerEntry; +import org.apache.directory.server.core.partition.Partition; +import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex; +import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; +import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException; +import org.apache.directory.shared.ldap.name.LdapDN; +import org.qi4j.api.configuration.Configuration; +import org.qi4j.api.injection.scope.This; +import org.qi4j.api.service.ServiceActivation; + +public class ApacheDirectoryServiceMixin + implements ServiceActivation, Ldap +{ + @This private Configuration configuration; + + /** + * The directory service + */ + private DirectoryService service; + private boolean running; + + public ApacheDirectoryServiceMixin() + { + System.out.println( "Starting LDAP." ); + } + + public void activateService() + throws Exception + { + // Initialize the LDAP service + service = new DefaultDirectoryService(); + + // Disable the ChangeLog system + service.getChangeLog().setEnabled( false ); + + + LdapConfiguration conf = configuration.get(); + String partitionId = conf.partitionId().get(); + Partition partition = addPartition( partitionId, conf.partitionDn().get() ); + + // Index some attributes on the apache partition + String[] attrs = { "objectClass", "ou", "uid" }; + addIndex( partition, attrs ); + addIndex( partition, configAttributes() ); + + // Inject the apache root entry if it does not already exist + try + { + service.getAdminSession().lookup( partition.getSuffixDn() ); + } + catch( LdapNameNotFoundException lnnfe ) + { + + LdapDN dnApache = new LdapDN( "dc=Apache,dc=Org" ); + ServerEntry entryApache = service.newEntry( dnApache ); + entryApache.add( "objectClass", "top", "domain", "extensibleObject" ); + entryApache.add( "dc", "Apache" ); + service.getAdminSession().add( entryApache ); + } + service.startup(); + running = true; + } + + private String[] configAttributes() + { + String attrs = configuration.get().indexAttributes().get(); + return attrs.split( "," ); + } + + public void passivateService() + throws Exception + { + running = false; + service.shutdown(); + } + + + /** + * Add a new partition to the server + * + * @param partitionId The partition Id + * @param partitionDn The partition DN + * @return The newly added partition + * @throws Exception If the partition can't be added + */ + private Partition addPartition( String partitionId, String partitionDn ) throws Exception + { + Partition partition = new JdbmPartition(); + partition.setId( partitionId ); + partition.setSuffix( partitionDn ); + service.addPartition( partition ); + + return partition; + } + + /** + * Add a new set of index on the given attributes + * + * @param partition The partition on which we want to add index + * @param attrs The list of attributes to index + */ + private void addIndex( Partition partition, String... attrs ) + { + // Index some attributes on the apache partition + Set indexedAttributes = new HashSet(); + + for( String attribute : attrs ) + { + indexedAttributes.add( new JdbmIndex( attribute ) ); + } + + ( (JdbmPartition) partition ).setIndexedAttributes( indexedAttributes ); + } + + public boolean isRunning() + { + return running; + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/Ldap.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/Ldap.java b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/Ldap.java new file mode 100644 index 0000000..e31392e --- /dev/null +++ b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/Ldap.java @@ -0,0 +1,24 @@ +/* + * Copyright 2009 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.ldap.server; + +public interface Ldap +{ + boolean isRunning(); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapConfiguration.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapConfiguration.java b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapConfiguration.java new file mode 100644 index 0000000..4973f27 --- /dev/null +++ b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapConfiguration.java @@ -0,0 +1,32 @@ +/* + * Copyright 2009 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.ldap.server; + +import org.qi4j.api.common.Optional; +import org.qi4j.api.configuration.ConfigurationComposite; +import org.qi4j.api.property.Property; + +public interface LdapConfiguration extends ConfigurationComposite +{ + Property partitionId(); + + Property partitionDn(); + + @Optional Property indexAttributes(); + +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapService.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapService.java b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapService.java new file mode 100644 index 0000000..fceab2d --- /dev/null +++ b/qi4j/libraries/ldap/server/src/main/java/org/qi4j/library/ldap/server/LdapService.java @@ -0,0 +1,27 @@ +/* + * Copyright 2009 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.ldap.server; + +import org.qi4j.api.mixin.Mixins; +import org.qi4j.api.service.ServiceActivation; + +@Mixins( ApacheDirectoryServiceMixin.class ) +public interface LdapService extends Ldap, ServiceActivation +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/src/test/java/org/qi4j/library/ldap/server/LdapServerTest.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/src/test/java/org/qi4j/library/ldap/server/LdapServerTest.java b/qi4j/libraries/ldap/server/src/test/java/org/qi4j/library/ldap/server/LdapServerTest.java new file mode 100644 index 0000000..2b808ee --- /dev/null +++ b/qi4j/libraries/ldap/server/src/test/java/org/qi4j/library/ldap/server/LdapServerTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2009 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.qi4j.library.ldap.server; + +import org.junit.Ignore; +import org.junit.Test; +import org.qi4j.bootstrap.AssemblyException; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.test.AbstractQi4jTest; + +public class LdapServerTest + extends AbstractQi4jTest +{ + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.services( LdapService.class ).instantiateOnStartup(); + module.entities( LdapConfiguration.class ); + } + + @Test + @Ignore + public void keepServerRunning() + throws Exception + { + long time = System.currentTimeMillis() + 120000; + while( true ) + { + if( System.currentTimeMillis() > time ) + { + break; + } + } + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/ldap/server/src/test/resources/org/qi4j/library/ldap/server/LdapService.properties ---------------------------------------------------------------------- diff --git a/qi4j/libraries/ldap/server/src/test/resources/org/qi4j/library/ldap/server/LdapService.properties b/qi4j/libraries/ldap/server/src/test/resources/org/qi4j/library/ldap/server/LdapService.properties new file mode 100644 index 0000000..12555b1 --- /dev/null +++ b/qi4j/libraries/ldap/server/src/test/resources/org/qi4j/library/ldap/server/LdapService.properties @@ -0,0 +1,2 @@ +partitionId=qi4j +partitionDn=dc=qi4j,dc=org http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/observations/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/observations/pom.xml b/qi4j/libraries/observations/pom.xml new file mode 100644 index 0000000..db4f755 --- /dev/null +++ b/qi4j/libraries/observations/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + org.qi4j.sandbox + qi4j-sandbox-libraries + 0-SNAPSHOT + + org.qi4j.library + org.qi4j.library.observations + Qi4j Library - Event/Observation Handling + + + + org.qi4j.core + org.qi4j.core.api + + + org.qi4j.library + org.qi4j.library.exception + ${project.version} + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/MulticastObserver.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/MulticastObserver.java b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/MulticastObserver.java new file mode 100644 index 0000000..6996319 --- /dev/null +++ b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/MulticastObserver.java @@ -0,0 +1,99 @@ +/* + * Copyright 2008 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.observations; + +import org.qi4j.api.common.Optional; +import org.qi4j.api.composite.Composite; +import org.qi4j.api.injection.scope.Service; +import org.qi4j.api.injection.scope.This; +import org.qi4j.library.exception.ExceptionHandling; + +import java.util.ArrayList; + +class MulticastObserver + implements Observer, Observable +{ + @Optional @Service private ExceptionHandling exceptionHandling; + @This private Composite meAsComposite; + + private ArrayList> observers; + + public MulticastObserver( Observer existing ) + { + observers = new ArrayList>(); + observers.add( existing ); + } + + public void notify( T observation ) + { + for( Observer observer : observers ) + { + try + { + observer.notify( observation ); + } + catch( Exception e ) + { + handleException( e, observer ); + } + } + } + + private void handleException( Exception exception, Observer observer ) + { + if( exceptionHandling != null ) + { + exceptionHandling.exceptionOccurred( "Exception in observer: " + observer, meAsComposite, exception ); + } + else + { + } + } + + public void addObserver( Observer observer ) + { + synchronized( this ) + { + ArrayList> clone = new ArrayList>(); + clone.addAll( observers ); + clone.add( observer ); + observers = clone; + } + } + + public void removeObserver( Observer observer ) + { + synchronized( this ) + { + ArrayList> clone = new ArrayList>(); + clone.addAll( observers ); + clone.remove( observer ); + observers = clone; + } + } + + boolean isOnlyOneLeft() + { + return observers.size() == 1; + } + + Observer getFirstOne() + { + return observers.get( 0 ); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observable.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observable.java b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observable.java new file mode 100644 index 0000000..bd1cde4 --- /dev/null +++ b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observable.java @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.observations; + +import org.qi4j.api.mixin.Mixins; + + +@Mixins( ObservableMixin.class ) +public interface Observable +{ + void addObserver( Observer observer ); + + void removeObserver( Observer observer ); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/ObservableMixin.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/ObservableMixin.java b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/ObservableMixin.java new file mode 100644 index 0000000..840523d --- /dev/null +++ b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/ObservableMixin.java @@ -0,0 +1,99 @@ +/* + * Copyright 2008 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.observations; + +import org.qi4j.api.common.Optional; +import org.qi4j.api.composite.Composite; +import org.qi4j.api.injection.scope.Service; +import org.qi4j.api.injection.scope.This; +import org.qi4j.library.exception.ExceptionHandling; + +public class ObservableMixin + implements Observable, Observer +{ + @Optional @Service private ExceptionHandling exceptionHandling; + @This private Composite meAsComposite; + + private Observer observer; + + public void addObserver( Observer observer ) + { + synchronized( this ) + { + if( this.observer == null ) + { + this.observer = observer; + return; + } + if( this.observer instanceof MulticastObserver ) + { + ( (MulticastObserver) this.observer ).addObserver( observer ); + return; + } + Observer existing = this.observer; + this.observer = new MulticastObserver( existing ); + } + } + + public void removeObserver( Observer observer ) + { + synchronized( this ) + { + if( this.observer == null ) + { + return; + } + if( this.observer instanceof MulticastObserver ) + { + MulticastObserver multicastObserver = (MulticastObserver) this.observer; + multicastObserver.removeObserver( observer ); + if( multicastObserver.isOnlyOneLeft() ) + { + this.observer = multicastObserver.getFirstOne(); + } + return; + } + if( this.observer.equals( observer ) ) + { + this.observer = null; + } + } + } + + public void notify( T observation ) + { + if( observer == null ) + { + return; + } + try + { + observer.notify( observation ); + } + catch( Exception e ) + { + if( exceptionHandling != null ) + { + exceptionHandling.exceptionOccurred( "Exception in observer: " + observer, meAsComposite, e ); + } + else + { + } + } + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observation.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observation.java b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observation.java new file mode 100644 index 0000000..6ba0cf4 --- /dev/null +++ b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observation.java @@ -0,0 +1,22 @@ +/* + * Copyright 2008 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.observations; + +public interface Observation +{ +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observer.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observer.java b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observer.java new file mode 100644 index 0000000..a9e2d18 --- /dev/null +++ b/qi4j/libraries/observations/src/main/java/org/qi4j/library/observations/Observer.java @@ -0,0 +1,23 @@ +/* + * Copyright 2008 Niclas Hedhman. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.observations; + +public interface Observer +{ + void notify( T observation ); +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/pom.xml b/qi4j/libraries/pom.xml new file mode 100644 index 0000000..e7297e7 --- /dev/null +++ b/qi4j/libraries/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + org.qi4j.sandbox + qi4j-sandbox + 0-SNAPSHOT + + qi4j-sandbox-libraries + Qi4j Sandbox Libraries - Build POM + pom + + + beans + entityproxy + exception + executor + ldap + observations + registry + rmi + thread + unitofwork + validation + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/registry/dev-status.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/registry/dev-status.xml b/qi4j/libraries/registry/dev-status.xml new file mode 100644 index 0000000..1e523b4 --- /dev/null +++ b/qi4j/libraries/registry/dev-status.xml @@ -0,0 +1,14 @@ + + + + early + + none + + none + + + + ALv2 + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/registry/pom.xml ---------------------------------------------------------------------- diff --git a/qi4j/libraries/registry/pom.xml b/qi4j/libraries/registry/pom.xml new file mode 100644 index 0000000..6a8493d --- /dev/null +++ b/qi4j/libraries/registry/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + org.qi4j.sandbox + qi4j-sandbox-libraries + 0-SNAPSHOT + + org.qi4j.library + org.qi4j.library.registry + Qi4j Library - Registry + + + + org.qi4j.core + org.qi4j.core.api + + + org.qi4j.library + org.qi4j.library.exception + ${project.version} + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/d4dd9c17/qi4j/libraries/registry/src/main/java/org/qi4j/library/registry/Registry.java ---------------------------------------------------------------------- diff --git a/qi4j/libraries/registry/src/main/java/org/qi4j/library/registry/Registry.java b/qi4j/libraries/registry/src/main/java/org/qi4j/library/registry/Registry.java new file mode 100644 index 0000000..a01c7b0 --- /dev/null +++ b/qi4j/libraries/registry/src/main/java/org/qi4j/library/registry/Registry.java @@ -0,0 +1,31 @@ +/* + * Copyright 2008 Niclas Hedhman. All rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.qi4j.library.registry; + +public interface Registry +{ + V lookup( K key ); + + void register( K key, V value ); + + void unregister( K key ); + + void addRegistryObserver( RegistryObserver observer ); + + void removeRegistryObserver( RegistryObserver observer ); +}