Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

Expand Down Expand Up @@ -706,6 +707,10 @@ public void unregisterRegionConfigurationSupport(

private final AtomicLong changeCount = new AtomicLong();

private final Object changeCountUpdateTaskLock = new Object();

private ScheduledFuture<?> changeCountUpdateTaskFuture;

private volatile ServiceRegistration<ServiceComponentRuntime> registration;

public Dictionary<String, Object> getServiceRegistrationProperties()
Expand All @@ -727,32 +732,43 @@ public void updateChangeCount()
{
final long count = this.changeCount.incrementAndGet();

try
synchronized ( changeCountUpdateTaskLock )
{
m_componentActor.schedule(new Runnable()
{
if ( changeCountUpdateTaskFuture != null && !changeCountUpdateTaskFuture.isDone() )
{
// If there is an uncompleted changcount update task already scheduled, cancel it to avoid
// unnecessary processing on the component actor thread
changeCountUpdateTaskFuture.cancel(false);
}

@Override
public void run()
try
{
changeCountUpdateTaskFuture = m_componentActor.schedule(new Runnable()
{
if ( changeCount.get() == count )

@Override
public void run()
{
try
if ( changeCount.get() == count )
{
registration.setProperties(getServiceRegistrationProperties());
}
catch ( final IllegalStateException ise)
{
// we ignore this as this might happen on shutdown
try
{
registration.setProperties(getServiceRegistrationProperties());
}
catch ( final IllegalStateException ise)
{
// we ignore this as this might happen on shutdown
}
}
}
}
}, m_configuration.serviceChangecountTimeout(), TimeUnit.MILLISECONDS);
}
catch (Exception e) {
m_logger.log(Level.WARN,
"Service changecount Timer for {0} had a problem", e,
registration.getReference());
}, m_configuration.serviceChangecountTimeout(), TimeUnit.MILLISECONDS);
}
catch (Exception e) {
m_logger.log(Level.WARN,
"Service changecount task for {0} had a problem", e,
registration.getReference());
}

}
}
}
Expand Down