Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/PlugTransportService.java
41161 views
/*1* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* A Super class for Transport Services used by25* nsk/jdi/PlugConnectors tests26*/2728package nsk.share.jdi;2930import com.sun.jdi.*;31import com.sun.jdi.connect.*;32import com.sun.jdi.connect.spi.*;33import java.io.*;34import java.util.*;3536public class PlugTransportService extends TransportService {3738String plugTransportServiceName = "Undefined_PlugTransportService_Name";39String plugTransportServiceDescription = "Undefined_PlugTransportService_Description";40TransportService.Capabilities plugTransportServiceCapabilities = new TestCapabilities();4142/*43* Simple implementation of TransportService.Capabilities44*/45public static class TestCapabilities extends TransportService.Capabilities {46boolean supportsAcceptTimeout = false;47boolean supportsAttachTimeout = false;48boolean supportsHandshakeTimeout = false;49boolean supportsMultipleConnections = false;5051public TestCapabilities() {52}5354public TestCapabilities(55boolean supportsAcceptTimeout,56boolean supportsAttachTimeout,57boolean supportsHandshakeTimeout,58boolean supportsMultipleConnections) {5960this.supportsAcceptTimeout = supportsAcceptTimeout;61this.supportsAttachTimeout = supportsAttachTimeout;62this.supportsHandshakeTimeout = supportsHandshakeTimeout;63this.supportsMultipleConnections = supportsMultipleConnections;64}6566public boolean supportsAcceptTimeout() {67return supportsAcceptTimeout;68}6970public boolean supportsAttachTimeout() {71return supportsAttachTimeout;72}7374public boolean supportsHandshakeTimeout() {75return supportsHandshakeTimeout;76}7778public boolean supportsMultipleConnections() {79return supportsMultipleConnections;80}8182} // end of TestCapabilities static class8384/*85* Simple implementation of TransportService.ListenKey86*/87public static class TestListenKey extends TransportService.ListenKey {88String address = null;8990public TestListenKey() {91}9293public TestListenKey(String address) {9495this.address = address;96}9798public String address() {99return address;100}101102} // end of TestListenKey static class103104public PlugTransportService() {105}106107public PlugTransportService(108String plugTransportServiceName,109String plugTransportServiceDescription,110TransportService.Capabilities plugTransportServiceCapabilities111) {112113this.plugTransportServiceName = plugTransportServiceName;114this.plugTransportServiceDescription = plugTransportServiceDescription;115this.plugTransportServiceCapabilities = plugTransportServiceCapabilities;116}117118public String name() {119return plugTransportServiceName;120}121122public String description() {123return plugTransportServiceDescription;124}125126public TransportService.Capabilities capabilities() {127return plugTransportServiceCapabilities;128}129130public Connection attach(131String address,132long attachTimeout,133long handshakeTimeout) throws IOException {134135String exceptionMessage = "## PlugTransportService: TransportService name = '" +136plugTransportServiceName + "';\nNon-authorized call of attach(...) method!";137138if ( true ) {139throw new RuntimeException(exceptionMessage);140}141142return null;143}144145public TransportService.ListenKey startListening(String address) throws IOException {146147String exceptionMessage = "## PlugTransportService: TransportService name = '" +148plugTransportServiceName + "';\nNon-authorized call of startListening(...) method!";149150if ( true ) {151throw new RuntimeException(exceptionMessage);152}153154return null;155}156157public TransportService.ListenKey startListening() throws IOException {158159String exceptionMessage = "## PlugTransportService: TransportService name = '" +160plugTransportServiceName + "';\nNon-authorized call of startListening() method!";161162if ( true ) {163throw new RuntimeException(exceptionMessage);164}165166return null;167}168169public void stopListening(TransportService.ListenKey listenKey) throws IOException {170171String exceptionMessage = "## PlugTransportService: TransportService name = '" +172plugTransportServiceName + "';\nNon-authorized call of stopListening() method!";173174if ( true ) {175throw new RuntimeException(exceptionMessage);176}177}178179public Connection accept(180TransportService.ListenKey listenKey,181long acceptTimeout,182long handshakeTimeout) throws IOException {183184String exceptionMessage = "## PlugTransportService: TransportService name = '" +185plugTransportServiceName + "';\nNon-authorized call of accept(...) method!";186187if ( true ) {188throw new RuntimeException(exceptionMessage);189}190191return null;192}193194/*195* Simple implementation of Connection196*/197public static class PlugTransportServiceConnection extends Connection {198199public void close() throws IOException {200String exceptionMessage =201"## PlugTransportConnection: \nNon-authorized call of close() method!";202203if ( true ) {204throw new RuntimeException(exceptionMessage);205}206}207208public boolean isOpen() {209String exceptionMessage =210"## PlugTransportConnection: \nNon-authorized call of isOpen() method!";211212if ( true ) {213throw new RuntimeException(exceptionMessage);214}215return false;216}217218public byte[] readPacket() throws IOException {219String exceptionMessage =220"## PlugTransportConnection: \nNon-authorized call of readPacket() method!";221222if ( true ) {223throw new ClosedConnectionException(exceptionMessage);224}225226if ( true ) {227throw new ClosedConnectionException();228}229230return null;231}232233public void writePacket(byte[] pkt) throws IOException {234String exceptionMessage =235"## PlugTransportConnection: \nNon-authorized call of writePacket(...) method!";236237if ( true ) {238throw new ClosedConnectionException(exceptionMessage);239}240241if ( true ) {242throw new ClosedConnectionException();243}244245}246247} // end of PlugTransportServiceConnection class248249} // end of PlugTransportService class250251252