You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/04/10 03:54:27 UTC
svn commit: r1090728 - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry5/internal/services/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/
tapestry-ioc/src...
Author: hlship
Date: Sun Apr 10 01:54:26 2011
New Revision: 1090728
URL: http://svn.apache.org/viewvc?rev=1090728&view=rev
Log:
TAP5-853: Convert ObjectCreator into a generic interface
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ApplicationMessageCatalogObjectProvider.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ObjectCreator.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/CachingObjectCreator.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ParallelExecutorImpl.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ApplicationMessageCatalogObjectProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ApplicationMessageCatalogObjectProvider.java?rev=1090728&r1=1090727&r2=1090728&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ApplicationMessageCatalogObjectProvider.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ApplicationMessageCatalogObjectProvider.java Sun Apr 10 01:54:26 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -49,9 +49,9 @@ public class ApplicationMessageCatalogOb
private Messages proxy;
- private class ApplicationMessagesObjectCreator implements ObjectCreator
+ private class ApplicationMessagesObjectCreator implements ObjectCreator<Messages>
{
- public Object createObject()
+ public Messages createObject()
{
Locale locale = threadLocale.getLocale();
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ObjectCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ObjectCreator.java?rev=1090728&r1=1090727&r2=1090728&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ObjectCreator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ObjectCreator.java Sun Apr 10 01:54:26 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2011 The Apache Software Foundation
//
// 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
+// 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,
@@ -17,11 +17,11 @@ package org.apache.tapestry5.ioc;
/**
* Interface used to encapsulate any strategy used defer the creation of some object until just as needed.
*/
-public interface ObjectCreator
+public interface ObjectCreator<T>
{
/**
- * Create and return the object. In some limited circumstances, the implementation may cache the result, returning
+ * Create and return the object. In some limited circumstances, the implementation may cache the result, returning
* the same object for repeated calls.
*/
- Object createObject();
+ T createObject();
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=1090728&r1=1090727&r2=1090728&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java Sun Apr 10 01:54:26 2011
@@ -1030,19 +1030,19 @@ public class RegistryImpl implements Reg
private <T> T createNonReloadingProxy(Class<T> interfaceClass, final Class<? extends T> implementationClass,
final ObjectLocator locator)
{
- final ObjectCreator autobuildCreator = new ObjectCreator()
+ final ObjectCreator<T> autobuildCreator = new ObjectCreator<T>()
{
- public Object createObject()
+ public T createObject()
{
return locator.autobuild(implementationClass);
}
};
- ObjectCreator justInTime = new ObjectCreator()
+ ObjectCreator<T> justInTime = new ObjectCreator<T>()
{
- private Object delegate;
+ private T delegate;
- public synchronized Object createObject()
+ public synchronized T createObject()
{
if (delegate == null)
delegate = autobuildCreator.createObject();
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/CachingObjectCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/CachingObjectCreator.java?rev=1090728&r1=1090727&r2=1090728&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/CachingObjectCreator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/CachingObjectCreator.java Sun Apr 10 01:54:26 2011
@@ -1,10 +1,10 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2011 The Apache Software Foundation
//
// 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
+// 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,
@@ -17,23 +17,23 @@ package org.apache.tapestry5.ioc.interna
import org.apache.tapestry5.ioc.ObjectCreator;
/**
- * An {@link org.apache.tapestry5.ioc.ObjectCreator} that delegates to another {@link
- * org.apache.tapestry5.ioc.ObjectCreator} and caches the result.
+ * An {@link org.apache.tapestry5.ioc.ObjectCreator} that delegates to another
+ * {@link org.apache.tapestry5.ioc.ObjectCreator} and caches the result.
*/
-public class CachingObjectCreator implements ObjectCreator
+public class CachingObjectCreator<T> implements ObjectCreator<T>
{
private boolean cached;
- private Object cachedValue;
+ private T cachedValue;
- private ObjectCreator delegate;
+ private ObjectCreator<T> delegate;
- public CachingObjectCreator(ObjectCreator delegate)
+ public CachingObjectCreator(ObjectCreator<T> delegate)
{
this.delegate = delegate;
}
- public synchronized Object createObject()
+ public synchronized T createObject()
{
if (!cached)
{
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java?rev=1090728&r1=1090727&r2=1090728&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java Sun Apr 10 01:54:26 2011
@@ -1,10 +1,10 @@
-// Copyright 2007, 2009 The Apache Software Foundation
+// Copyright 2007, 2009, 2011 The Apache Software Foundation
//
// 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
+// 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,
@@ -26,19 +26,17 @@ import org.apache.tapestry5.ioc.services
* same time (a service should be realized only once). The additional interfaces implemented by this class support eager
* loading of services (at application startup), and orderly shutdown of proxies.
*/
-public class JustInTimeObjectCreator implements ObjectCreator, EagerLoadServiceProxy,
- RegistryShutdownListener
+public class JustInTimeObjectCreator<T> implements ObjectCreator<T>, EagerLoadServiceProxy, RegistryShutdownListener
{
private final ServiceActivityTracker tracker;
- private volatile ObjectCreator creator;
+ private volatile ObjectCreator<T> creator;
- private volatile Object object;
+ private volatile T object;
private final String serviceId;
- public JustInTimeObjectCreator(ServiceActivityTracker tracker, ObjectCreator creator,
- String serviceId)
+ public JustInTimeObjectCreator(ServiceActivityTracker tracker, ObjectCreator<T> creator, String serviceId)
{
this.tracker = tracker;
this.creator = creator;
@@ -48,10 +46,11 @@ public class JustInTimeObjectCreator imp
/**
* Checks to see if the proxy has been shutdown, then invokes {@link ObjectCreator#createObject()} if it has not
* already done so.
- *
- * @throws IllegalStateException if the registry has been shutdown
+ *
+ * @throws IllegalStateException
+ * if the registry has been shutdown
*/
- public Object createObject()
+ public T createObject()
{
if (object == null)
obtainObjectFromCreator();
@@ -61,7 +60,8 @@ public class JustInTimeObjectCreator imp
private synchronized void obtainObjectFromCreator()
{
- if (object != null) return;
+ if (object != null)
+ return;
try
{
@@ -94,9 +94,9 @@ public class JustInTimeObjectCreator imp
*/
public void registryDidShutdown()
{
- creator = new ObjectCreator()
+ creator = new ObjectCreator<T>()
{
- public Object createObject()
+ public T createObject()
{
throw new IllegalStateException(ServiceMessages.registryShutdown(serviceId));
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ParallelExecutorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ParallelExecutorImpl.java?rev=1090728&r1=1090727&r2=1090728&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ParallelExecutorImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ParallelExecutorImpl.java Sun Apr 10 01:54:26 2011
@@ -1,10 +1,10 @@
-// Copyright 2009, 2010 The Apache Software Foundation
+// Copyright 2009, 2010, 2011 The Apache Software Foundation
//
// 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
+// 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,
@@ -33,7 +33,7 @@ public class ParallelExecutorImpl implem
private final PerthreadManager perthreadManager;
public ParallelExecutorImpl(ExecutorService executorService, ThunkCreator thunkCreator,
- PerthreadManager perthreadManager)
+ PerthreadManager perthreadManager)
{
this.executorService = executorService;
this.thunkCreator = thunkCreator;
@@ -69,9 +69,9 @@ public class ParallelExecutorImpl implem
{
final Future<T> future = invoke(invocable);
- ObjectCreator creator = new ObjectCreator()
+ ObjectCreator<T> creator = new ObjectCreator<T>()
{
- public Object createObject()
+ public T createObject()
{
try
{