Skip to content

Commit

Permalink
Fixed @singleton compile errors and conditional observers
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@555 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
drallen committed Dec 18, 2008
1 parent e1f42ef commit 636f062
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 173 deletions.
11 changes: 9 additions & 2 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -450,7 +450,7 @@ public <T> T getInstance(Bean<T> bean)
{
if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
{
return (T) proxyPool.getClientProxy(bean);
return (T) proxyPool.getClientProxy(bean, true);
}
else
{
Expand Down Expand Up @@ -502,7 +502,14 @@ public <T> T getInstanceByType(Class<T> type, Annotation... bindings)
public <T> T getMostSpecializedInstance(Bean<T> bean, boolean create)
{
// TODO Implement specialization
return getInstance(bean);
if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
{
return (T) proxyPool.getClientProxy(bean, create);
}
else
{
return getContext(bean.getScopeType()).get(bean, create);
}
}

/**
Expand Down
Expand Up @@ -139,27 +139,37 @@ private static <T> T createClientProxy(Bean<T> bean, int beanIndex) throws Runti
* Gets a client proxy for a bean
*
* Looks for a proxy in the pool. If not found, one is created and added to
* the pool
* the pool if the create argument is true.
*
* @param bean
* @return
* @param bean The bean to get a proxy to
* @param create Flag indicating if the proxy should be created if it does
* not already exist
* @return the client proxy for the bean
*/
public <T> T getClientProxy(final Bean<T> bean)
@SuppressWarnings("unchecked")
public <T> T getClientProxy(final Bean<T> bean, boolean create)
{
return pool.putIfAbsent(bean, new Callable<T>()
if (create)
{

public T call() throws Exception
return pool.putIfAbsent(bean, new Callable<T>()
{
int beanIndex = CurrentManager.rootManager().getBeans().indexOf(bean);
if (beanIndex < 0)

public T call() throws Exception
{
throw new DefinitionException(bean + " is not known to the manager");
int beanIndex = CurrentManager.rootManager().getBeans().indexOf(bean);
if (beanIndex < 0)
{
throw new DefinitionException(bean + " is not known to the manager");
}
return createClientProxy(bean, beanIndex);
}
return createClientProxy(bean, beanIndex);
}

});

});
}
else
{
return (T)pool.getValue(bean);
}
}

/**
Expand Down
Expand Up @@ -221,7 +221,7 @@ public <T> void notifyObservers(Set<Observer<T>> observers, T event)
DependentContext.INSTANCE.setActive(true);
for (Observer<T> observer : observers)
{
if (isTransactionActive() && ((ObserverImpl<?>) observer).isTransactional())
if ((observer instanceof ObserverImpl) && isTransactionActive() && ((ObserverImpl<?>) observer).isTransactional())
{
deferEvent(event, observer);
}
Expand Down
Expand Up @@ -166,7 +166,7 @@ private void validateObserverMethod()
public void notify(final T event)
{
// Get the most specialized instance of the component
Object instance = getInstance(isConditional());
Object instance = getInstance(!isConditional());
if (instance != null)
{
try
Expand Down Expand Up @@ -195,14 +195,14 @@ public void notify(final T event)
* Uses the container to retrieve the most specialized instance of this
* observer.
*
* @param conditional T
* @param create True if the instance should be created if not already done
*
* @return the most specialized instance
*/
protected Object getInstance(boolean conditional)
protected Object getInstance(boolean create)
{
// Return the most specialized instance of the component
return manager.getMostSpecializedInstance(eventBean, conditional);
return manager.getMostSpecializedInstance(eventBean, create);
}

/**
Expand Down
Expand Up @@ -57,7 +57,7 @@ public <T extends V> Future<T> getFuture(K key)
{
return (Future<T>) super.get(key);
}

/**
* Gets a value from the map. Blocks until it is available
*
Expand All @@ -68,34 +68,42 @@ public <T extends V> Future<T> getFuture(K key)
public <T extends V> T getValue(K key)
{
Future<T> value = (Future<T>) map.get(key);
boolean interrupted = false;
try
if (value != null)
{
while (true)
boolean interrupted = false;
try
{
try
while (true)
{
return value.get();
try
{
return value.get();
}
catch (InterruptedException e)
{
interrupted = true;
}
catch (ExecutionException e)
{
rethrow(e);
}
;
}
catch (InterruptedException e)
}
finally
{
if (interrupted)
{
interrupted = true;
Thread.currentThread().interrupt();
}
catch (ExecutionException e)
{
rethrow(e);
};
}
}
finally
else
{
if (interrupted)
{
Thread.currentThread().interrupt();
}
return null;
}
}

/**
* Adds an item to the map if it's not already there
Expand Down Expand Up @@ -130,7 +138,8 @@ public <E> E putIfAbsent(K key, Callable<E> callable)
catch (ExecutionException e)
{
rethrow(e);
};
}
;
}
}
finally
Expand All @@ -152,7 +161,7 @@ protected Map<K, Future<V>> delegate()
{
return map;
}

/**
* Examines and re-throws an exception
*
Expand Down

0 comments on commit 636f062

Please sign in to comment.