Skip to content

FELIX-6778 Reduce number of re-creation(s) of SCR Component Registry thread #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 4 additions & 10 deletions scr/src/main/java/org/apache/felix/scr/impl/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class Activator extends AbstractExtender
private ComponentRegistry m_componentRegistry;

// thread acting upon configurations
private ComponentActorThread m_componentActor;
private ComponentActorExecutor m_componentActor;

private ServiceRegistration<ServiceComponentRuntime> m_runtime_reg;

Expand Down Expand Up @@ -210,7 +210,8 @@ protected void doStart() throws Exception

// prepare component registry
m_componentBundles = new HashMap<>();
m_componentRegistry = new ComponentRegistry( this.m_configuration, this.logger );
m_componentActor = new ComponentActorExecutor( this.logger );
m_componentRegistry = new ComponentRegistry( this.m_configuration, this.logger, this.m_componentActor );

final ServiceComponentRuntimeImpl runtime = new ServiceComponentRuntimeImpl( m_globalContext, m_componentRegistry );
m_runtime_reg = m_context.registerService( ServiceComponentRuntime.class,
Expand All @@ -222,12 +223,6 @@ protected void doStart() throws Exception
logger.log(Level.INFO, " Version = {0}",
null, m_bundle.getVersion().toString() );

// create and start the component actor
m_componentActor = new ComponentActorThread( this.logger );
Thread t = new Thread( m_componentActor, "SCR Component Actor" );
t.setDaemon( true );
t.start();

super.doStart();

m_componentCommands = new ComponentCommands(m_context, runtime, m_configuration);
Expand Down Expand Up @@ -427,14 +422,13 @@ public void doStop() throws Exception
// dispose component registry
if ( m_componentRegistry != null )
{
m_componentRegistry.shutdown();
m_componentRegistry = null;
}

// terminate the actor thread
if ( m_componentActor != null )
{
m_componentActor.terminate();
m_componentActor.shutdownNow();
m_componentActor = null;
}
ClassUtils.setFrameworkWiring(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.StringTokenizer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class BundleComponentActivator implements ComponentActivator
private final List<ComponentHolder<?>> m_holders = new ArrayList<>();

// thread acting upon configurations
private final ComponentActorThread m_componentActor;
private final ScheduledExecutorService m_componentActor;

// true as long as the dispose method is not called
private final AtomicBoolean m_active = new AtomicBoolean( true );
Expand Down Expand Up @@ -196,7 +197,7 @@ public void removeServiceListener(String serviceFilterString,
*/
public BundleComponentActivator(final ScrLogger scrLogger,
final ComponentRegistry componentRegistry,
final ComponentActorThread componentActor,
final ScheduledExecutorService componentActor,
final BundleContext context,
final ScrConfiguration configuration,
final List<ComponentMetadata> cachedComponentMetadata,
Expand Down Expand Up @@ -712,10 +713,10 @@ public void schedule(Runnable task)
{
if ( isActive() )
{
ComponentActorThread cat = m_componentActor;
ScheduledExecutorService cat = m_componentActor;
if ( cat != null )
{
cat.schedule( task );
cat.submit( task );
}
else
{
Expand Down Expand Up @@ -762,7 +763,7 @@ public <T> void leaveCreate(ServiceReference<T> serviceReference)
@Override
public <T> void missingServicePresent(ServiceReference<T> serviceReference)
{
m_componentRegistry.missingServicePresent( serviceReference, m_componentActor );
m_componentRegistry.missingServicePresent( serviceReference );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.felix.scr.impl;


import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;

import org.apache.felix.scr.impl.logger.InternalLogger.Level;
import org.apache.felix.scr.impl.logger.ScrLogger;


/**
* The <code>ComponentActorExecutor</code> is the thread used to act upon registered
* components of the service component runtime.
* This is also used by the ComponentRegistry to schedule service.changecount updates.
*/
class ComponentActorExecutor extends ScheduledThreadPoolExecutor
{

private static final ThreadFactory THREAD_FACTORY = new ThreadFactory()
{
@Override
public Thread newThread(Runnable r)
{
Thread thread = new Thread(r, "SCR Component Actor");
thread.setDaemon(true);
return thread;
}
};

private final ScrLogger logger;

ComponentActorExecutor(final ScrLogger log )
{
super( 1, THREAD_FACTORY );
logger = log;
}

@Override
protected void beforeExecute(Thread t, Runnable r)
{
logger.log(Level.DEBUG, "Running task: " + r, null);
}

@Override
protected void afterExecute(Runnable r, Throwable t)
{
if (t != null)
{
logger.log(Level.ERROR, "Unexpected problem executing task " + r, t);
}
}
}
179 changes: 0 additions & 179 deletions scr/src/main/java/org/apache/felix/scr/impl/ComponentActorThread.java

This file was deleted.

Loading