com.sun.xml.ws.transport.tcp.client.WSConnectionCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices-osgi Show documentation
Show all versions of webservices-osgi Show documentation
Metro Web Services Runtime OSGi Bundle
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.ws.transport.tcp.client;
import com.sun.istack.NotNull;
import com.sun.istack.Nullable;
import com.sun.xml.ws.transport.tcp.resources.MessagesMessages;
import com.sun.xml.ws.transport.tcp.util.SessionAbortedException;
import com.sun.xml.ws.transport.tcp.util.ConnectionSession;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Alexey Stashok
*/
public class WSConnectionCache {
// private static final Logger logger = Logger.getLogger(
// com.sun.xml.ws.transport.tcp.util.TCPConstants.LoggingDomain + ".client");
//
// // map contains all connection sessions to certain destination
// private final Map> allDstAddress2connectionSession;
//
// // map contains available connection sessions to certain destination (MAX_CHANNELS is not reached)
// private final Map> availableDstAddress2connectionSession;
//
// // set of locked connections, which are in use
// private final Map lockedConnections;
//
// public WSConnectionCache() {
// allDstAddress2connectionSession = new HashMap>();
// availableDstAddress2connectionSession = new HashMap>();
// lockedConnections = new HashMap();
// }
//
// public void registerConnectionSession(@NotNull final ConnectionSession connectionSession, final int dstAddrHashKey) {
// ConcurrentLinkedQueue availableConnectionSessions = availableDstAddress2connectionSession.get(dstAddrHashKey);
// Set allConnectionSessions = allDstAddress2connectionSession.get(dstAddrHashKey);
// synchronized(this) {
// //check if there is a record for such destination address
// if (allConnectionSessions == null) {
// allConnectionSessions = new HashSet();
// allDstAddress2connectionSession.put(dstAddrHashKey, allConnectionSessions);
// availableConnectionSessions = new ConcurrentLinkedQueue();
// availableDstAddress2connectionSession.put(dstAddrHashKey, availableConnectionSessions);
// }
// }
// availableConnectionSessions.offer(connectionSession);
// allConnectionSessions.add(connectionSession);
// }
//
// /**
// * Get all active sessions for given destination host:port
// */
// public @NotNull Set getAllConnectionsByAddr(final int dstAddrHashKey) {
// final Set allConnectionSessions = allDstAddress2connectionSession.get(dstAddrHashKey);
// return allConnectionSessions != null ? allConnectionSessions : Collections.emptySet();
// }
//
// /**
// * Get session, where it is available to create one more virtual connection
// */
// public @Nullable ConnectionSession pollAvailableConnectionByAddr(final int dstAddrHashKey) {
// final ConcurrentLinkedQueue availableConnectionSessions = availableDstAddress2connectionSession.get(dstAddrHashKey);
// return availableConnectionSessions != null ? availableConnectionSessions.poll() : null;
// }
//
// /**
// * Put back session to available session list
// */
// public void offerAvailableConnectionByAddr(@NotNull final ConnectionSession connectionSession, final int dstAddrHashKey) {
// final ConcurrentLinkedQueue availableConnectionSessions = availableDstAddress2connectionSession.get(dstAddrHashKey);
// availableConnectionSessions.offer(connectionSession);
// }
//
// /**
// * Destroy connection session
// */
// public void removeConnectionSession(final @NotNull ConnectionSession tcpConnectionSession) {
// final int addressHashKey = tcpConnectionSession.getDstAddressHashKey();
// final Set allConnectionSessions = allDstAddress2connectionSession.get(addressHashKey);
//
// // method is called before ConnectionSession was registered in cache
// if (allConnectionSessions != null) {
// final ConcurrentLinkedQueue availableConnectionSessions = availableDstAddress2connectionSession.get(addressHashKey);
//
// synchronized(tcpConnectionSession) {
// // remove session from all and available lists
// allConnectionSessions.remove(tcpConnectionSession);
// availableConnectionSessions.remove(tcpConnectionSession);
//
// unlockConnection(tcpConnectionSession);
// tcpConnectionSession.notifyAll();
// }
// }
// }
//
// public void lockConnection(final @NotNull ConnectionSession tcpConnectionSession) throws InterruptedException, SessionAbortedException {
// logger.log(Level.FINEST, MessagesMessages.WSTCP_1020_CONNECTION_CACHE_ENTER());
// final Thread lockedThread = lockedConnections.get(tcpConnectionSession);
// if (Thread.currentThread().equals(lockedThread)) return;
//
// synchronized(tcpConnectionSession) {
// logger.log(Level.FINEST, MessagesMessages.WSTCP_1021_CONNECTION_CACHE_SYNC());
// while(lockedConnections.containsKey(tcpConnectionSession)) {
// tcpConnectionSession.wait();
// }
//
// // check whether session was aborted?
// final Set allConnectionSessions = allDstAddress2connectionSession.get(tcpConnectionSession.getDstAddressHashKey());
// if (allConnectionSessions.contains(tcpConnectionSession)) {
// logger.log(Level.FINEST, MessagesMessages.WSTCP_1022_CONNECTION_CACHE_LOCK());
// lockedConnections.put(tcpConnectionSession, Thread.currentThread());
// } else {
// logger.log(Level.FINEST, MessagesMessages.WSTCP_1023_CONNECTION_CACHE_SESSION_ABORTED());
// throw new SessionAbortedException();
// }
// }
// }
//
// public void unlockConnection(final @NotNull ConnectionSession tcpConnectionSession) {
// synchronized(tcpConnectionSession) {
// lockedConnections.remove(tcpConnectionSession);
// tcpConnectionSession.notify();
// }
// }
}