io.joynr.messaging.routing.GarbageCollectionHandler Maven / Gradle / Ivy
The newest version!
/*
* #%L
* %%
* Copyright (C) 2021-2023 BMW Car IT GmbH
* %%
* 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.
* #L%
*/
package io.joynr.messaging.routing;
import static io.joynr.messaging.routing.MessageRouter.SCHEDULEDTHREADPOOL;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.google.inject.Singleton;
import io.joynr.exceptions.JoynrIllegalStateException;
import io.joynr.messaging.ConfigurableMessagingSettings;
import io.joynr.runtime.PrepareForShutdownListener;
import io.joynr.runtime.ShutdownListener;
import io.joynr.runtime.ShutdownNotifier;
@Singleton
public class GarbageCollectionHandler implements ShutdownListener {
private static final Logger logger = LoggerFactory.getLogger(GarbageCollectionHandler.class);
static class ProxyInformation {
public String participantId;
public PrepareForShutdownListener prepareForShutdownListener;
public final Set providerParticipantIds;
public ProxyInformation(String participantId, PrepareForShutdownListener prepareForShutdownListener) {
this.participantId = participantId;
this.prepareForShutdownListener = prepareForShutdownListener;
this.providerParticipantIds = new HashSet();
}
}
// Map weak reference to proxy object -> {proxyParticipantId, shutdownListener}
private final ConcurrentHashMap, ProxyInformation> proxyMap;
private final ConcurrentHashMap proxyParticipantIdToProxyInformationMap;
private final ReferenceQueue