├── .github └── dependabot.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── findbugs.excludes.xml ├── lib ├── gson-2.2.4.jar ├── logback-classic-1.1.2.jar ├── logback-core-1.1.2.jar ├── netty-all-4.0.21.Final.jar ├── slf4j-api-1.7.5.jar └── stateless4j-2.5.0.jar ├── mqlight-distribution ├── maven_install.cmd ├── maven_install.sh ├── pom.xml └── src │ └── assembly │ └── bin.xml ├── mqlight-samples ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── ibm │ │ └── mqlight │ │ └── api │ │ └── samples │ │ ├── ArgumentParser.java │ │ ├── Receive.java │ │ ├── Send.java │ │ └── UiWorkout.java │ └── test │ └── java │ └── com │ └── ibm │ └── mqlight │ └── api │ └── samples │ └── TestArgumentParser.java ├── mqlight ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── ibm │ │ └── mqlight │ │ └── api │ │ ├── BytesDelivery.java │ │ ├── ClientException.java │ │ ├── ClientOptions.java │ │ ├── ClientRuntimeException.java │ │ ├── ClientState.java │ │ ├── CompletionListener.java │ │ ├── Delivery.java │ │ ├── DestinationAdapter.java │ │ ├── DestinationListener.java │ │ ├── JsonDelivery.java │ │ ├── MalformedDelivery.java │ │ ├── NetworkException.java │ │ ├── NonBlockingClient.java │ │ ├── NonBlockingClientAdapter.java │ │ ├── NonBlockingClientListener.java │ │ ├── NotPermittedException.java │ │ ├── Promise.java │ │ ├── QOS.java │ │ ├── ReplacedException.java │ │ ├── SecurityException.java │ │ ├── SendOptions.java │ │ ├── StartingException.java │ │ ├── StateException.java │ │ ├── StoppedException.java │ │ ├── StringDelivery.java │ │ ├── SubscribeOptions.java │ │ ├── SubscribedException.java │ │ ├── UnsubscribedException.java │ │ ├── callback │ │ └── CallbackService.java │ │ ├── doc-files │ │ └── sm.gif │ │ ├── endpoint │ │ ├── Endpoint.java │ │ ├── EndpointPromise.java │ │ └── EndpointService.java │ │ ├── impl │ │ ├── BytesDeliveryImpl.java │ │ ├── CompletionFuture.java │ │ ├── Component.java │ │ ├── ComponentImpl.java │ │ ├── DeliveryImpl.java │ │ ├── DestinationListenerWrapper.java │ │ ├── FSMActions.java │ │ ├── InternalSend.java │ │ ├── InternalStart.java │ │ ├── InternalStop.java │ │ ├── InternalSubscribe.java │ │ ├── InternalUnsubscribe.java │ │ ├── JsonDeliveryImpl.java │ │ ├── LogbackLogging.java │ │ ├── MalformedDeliveryImpl.java │ │ ├── Message.java │ │ ├── NonBlockingClientImpl.java │ │ ├── NonBlockingClientListenerWrapper.java │ │ ├── NonBlockingClientState.java │ │ ├── NonBlockingClientTrigger.java │ │ ├── NonBlockingFSMFactory.java │ │ ├── QueueableWork.java │ │ ├── StringDeliveryImpl.java │ │ ├── SubscriptionTopic.java │ │ ├── callback │ │ │ ├── CallbackExceptionNotification.java │ │ │ ├── CallbackPromiseImpl.java │ │ │ ├── FlushResponse.java │ │ │ ├── SameThreadCallbackService.java │ │ │ └── ThreadPoolCallbackService.java │ │ ├── endpoint │ │ │ ├── BluemixEndpointService.java │ │ │ ├── EndpointImpl.java │ │ │ ├── EndpointPromiseImpl.java │ │ │ ├── EndpointResponse.java │ │ │ ├── EndpointServiceImpl.java │ │ │ ├── ExhaustedResponse.java │ │ │ └── SingleEndpointService.java │ │ ├── engine │ │ │ ├── CloseRequest.java │ │ │ ├── CloseResponse.java │ │ │ ├── DeliveryRequest.java │ │ │ ├── DeliveryResponse.java │ │ │ ├── DisconnectNotification.java │ │ │ ├── DrainNotification.java │ │ │ ├── Engine.java │ │ │ ├── EngineConnection.java │ │ │ ├── OpenRequest.java │ │ │ ├── OpenResponse.java │ │ │ ├── SendRequest.java │ │ │ ├── SendResponse.java │ │ │ ├── SubscribeRequest.java │ │ │ ├── SubscribeResponse.java │ │ │ ├── UnsubscribeRequest.java │ │ │ └── UnsubscribeResponse.java │ │ ├── logging │ │ │ ├── FFDC.java │ │ │ ├── Javacore.java │ │ │ ├── LogMarker.java │ │ │ ├── LoggerFactoryImpl.java │ │ │ ├── LoggerImpl.java │ │ │ ├── Version.java │ │ │ └── logback │ │ │ │ ├── ArgsConverter.java │ │ │ │ ├── ClientIdConverter.java │ │ │ │ ├── IndentConverter.java │ │ │ │ ├── LevelConverter.java │ │ │ │ ├── LogFilter.java │ │ │ │ ├── LogbackLoggingImpl.java │ │ │ │ ├── ObjectIdConverter.java │ │ │ │ ├── PIDConverter.java │ │ │ │ ├── TIDConverter.java │ │ │ │ └── TraceFilter.java │ │ ├── network │ │ │ ├── ConnectResponse.java │ │ │ ├── ConnectionError.java │ │ │ ├── DataRead.java │ │ │ ├── DisconnectResponse.java │ │ │ ├── NettyNetworkService.java │ │ │ ├── NetworkClosePromiseImpl.java │ │ │ ├── NetworkConnectPromiseImpl.java │ │ │ ├── NetworkListenerImpl.java │ │ │ ├── NetworkWritePromiseImpl.java │ │ │ ├── WriteResponse.java │ │ │ └── ssl │ │ │ │ └── SSLEngineFactory.java │ │ └── timer │ │ │ ├── CancelResponse.java │ │ │ ├── PopResponse.java │ │ │ ├── TimerPromiseImpl.java │ │ │ └── TimerServiceImpl.java │ │ ├── logging │ │ ├── FFDCProbeId.java │ │ ├── Logger.java │ │ └── LoggerFactory.java │ │ ├── network │ │ ├── NetworkChannel.java │ │ ├── NetworkListener.java │ │ └── NetworkService.java │ │ ├── package.html │ │ ├── resources │ │ └── mqlight-logback.xml │ │ ├── security │ │ ├── KeyStoreUtils.java │ │ └── PemFile.java │ │ └── timer │ │ └── TimerService.java │ └── test │ └── java │ └── com │ └── ibm │ └── mqlight │ └── api │ ├── TestClientOptions.java │ ├── TestNonBlockingClient.java │ ├── TestNonBlockingClientAdapter.java │ ├── TestSSLClientOptions.java │ ├── TestSendOptions.java │ ├── TestSubscribeOptions.java │ └── impl │ ├── MockComponent.java │ ├── TestDeliveryImpl.java │ ├── TestDestinationListenerWrapper.java │ ├── TestNonBlockingClientImpl.java │ ├── callback │ ├── MockCallbackPromise.java │ ├── TestCallbackPromiseImpl.java │ ├── TestSameThreadCallbackService.java │ └── TestThreadPoolCallbackService.java │ ├── endpoint │ ├── MockEndpointPromise.java │ ├── TestBluemixEndpointService.java │ ├── TestEndpointImpl.java │ ├── TestEndpointPromiseImpl.java │ └── TestSingleEndpointService.java │ ├── engine │ ├── MockNetworkChannel.java │ └── TestEngine.java │ ├── logging │ ├── MockEvent.java │ ├── MockLogger.java │ ├── TestLoggerImpl.java │ └── logback │ │ ├── MockILoggingEvent.java │ │ ├── TestArgsConverter.java │ │ ├── TestClientIdConverter.java │ │ ├── TestIndentConverter.java │ │ ├── TestLevelConverter.java │ │ ├── TestLogFilter.java │ │ ├── TestLogbackLoggingImpl.java │ │ ├── TestObjectIdlConverter.java │ │ ├── TestPIDConverter.java │ │ ├── TestTIDConverter.java │ │ └── TestTraceFilter.java │ ├── network │ ├── Event.java │ ├── MockNetworkClosePromise.java │ ├── MockNetworkConnectPromise.java │ ├── MockNetworkListener.java │ ├── MockNetworkWritePromise.java │ ├── TestNettyNetworkService.java │ ├── TestNetworkClosePromise.java │ ├── TestNetworkConnectPromiseImpl.java │ ├── TestNetworkListenerImpl.java │ └── TestNetworkWritePromiseImpl.java │ └── timer │ ├── TestTimerPromise.java │ └── TestTimerService.java └── pom.xml /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | ignore: 9 | - dependency-name: org.apache.qpid:proton-j 10 | versions: 11 | - 0.32.0 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | javacore.*.txt 11 | **/.classpath 12 | **/.project 13 | **/.settings 14 | **/bin 15 | .fbExcludeFilterFile 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: java 3 | jdk: 4 | - oraclejdk8 5 | - oraclejdk7 6 | sudo: false 7 | branches: 8 | only: 9 | - master 10 | -------------------------------------------------------------------------------- /findbugs.excludes.xml: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /lib/gson-2.2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/lib/gson-2.2.4.jar -------------------------------------------------------------------------------- /lib/logback-classic-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/lib/logback-classic-1.1.2.jar -------------------------------------------------------------------------------- /lib/logback-core-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/lib/logback-core-1.1.2.jar -------------------------------------------------------------------------------- /lib/netty-all-4.0.21.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/lib/netty-all-4.0.21.Final.jar -------------------------------------------------------------------------------- /lib/slf4j-api-1.7.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/lib/slf4j-api-1.7.5.jar -------------------------------------------------------------------------------- /lib/stateless4j-2.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/lib/stateless4j-2.5.0.jar -------------------------------------------------------------------------------- /mqlight-distribution/maven_install.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM 3 | REM Licensed to the Apache Software Foundation (ASF) under one 4 | REM or more contributor license agreements. See the NOTICE file 5 | REM distributed with this work for additional information 6 | REM regarding copyright ownership. The ASF licenses this file 7 | REM to you under the Apache License, Version 2.0 (the 8 | REM "License"); you may not use this file except in compliance 9 | REM with the License. You may obtain a copy of the License at 10 | REM 11 | REM http://www.apache.org/licenses/LICENSE-2.0 12 | REM 13 | REM Unless required by applicable law or agreed to in writing, 14 | REM software distributed under the License is distributed on an 15 | REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | REM KIND, either express or implied. See the License for the 17 | REM specific language governing permissions and limitations 18 | REM under the License. 19 | REM 20 | 21 | REM Install the MQ Light API to the local Maven repository 22 | call mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=mqlight-api-%version%.jar -DpomFile=mqlight/pom.xml 23 | 24 | REM Install the MQ Light API samples to the local Maven repository 25 | call mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=mqlight-api-samples-%version%.jar -DpomFile=mqlight-samples/pom.xml 26 | 27 | REM Install the MQ Light project to the local Maven repository 28 | REM This is necessary in order for other Maven projects depending on MQ Light to be able to build in offline mode 29 | call mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=pom.xml -DpomFile=pom.xml 30 | 31 | REM Install the required dependencies to the local Maven repository 32 | call mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -Dartifact=com.ibm.mqlight:mqlight-api:%version% 33 | -------------------------------------------------------------------------------- /mqlight-distribution/maven_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | 21 | # Install the MQ Light API to the local Maven repository 22 | mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=mqlight-api-$version.jar -DpomFile=mqlight/pom.xml 23 | 24 | # Install the MQ Light API samples to the local Maven repository 25 | mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=mqlight-api-samples-$version.jar -DpomFile=mqlight-samples/pom.xml 26 | 27 | # Install the MQ Light project to the local Maven repository 28 | # This is necessary in order for other Maven projects depending on MQ Light to be able to build in offline mode 29 | mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=pom.xml -DpomFile=pom.xml 30 | 31 | # Install the required dependencies to the local Maven repository 32 | mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -Dartifact=com.ibm.mqlight:mqlight-api:$version -DrepoUrl=http://repo1.maven.org/maven2/ -------------------------------------------------------------------------------- /mqlight-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 26 | 27 | com.ibm.mqlight 28 | mqlight-project 29 | 1.0-SNAPSHOT 30 | 31 | 32 | 4.0.0 33 | 34 | mqlight-api-samples 35 | 36 | ${project.groupId}:${project.artifactId} 37 | MQ Light Java API Samples. 38 | 39 | 40 | 41 | com.ibm.mqlight 42 | mqlight-api 43 | ${project.parent.version} 44 | 45 | 46 | junit 47 | junit 48 | 4.13.2 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.codehaus.mojo 58 | findbugs-maven-plugin 59 | 60 | 61 | 62 | 63 | org.codehaus.mojo 64 | xml-maven-plugin 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/BytesDelivery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | import java.nio.ByteBuffer; 22 | 23 | /** 24 | * A sub-type of delivery that is used to represent binary data being received 25 | * by the client. 26 | */ 27 | public interface BytesDelivery extends Delivery { 28 | /** 29 | * @return a byte buffer containing a message pay-load data. Logically, this buffer 30 | * belongs to application at the point this object is supplied to the 31 | * DeliveryListener. That is to say that once passed to the 32 | * DeliveryListener the client will never modify the data held 33 | * in this buffer. 34 | */ 35 | ByteBuffer getData(); 36 | } 37 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/ClientException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Superclass of all MQ Light specific client checked exceptions 23 | */ 24 | public class ClientException extends Exception { 25 | 26 | private static final long serialVersionUID = 5343791367613494183L; 27 | 28 | public ClientException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | 32 | public ClientException(String message) { 33 | super(message); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/ClientRuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Superclass of all MQ Light specific client unchecked exceptions 23 | */ 24 | public class ClientRuntimeException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = -7670482333474200402L; 27 | 28 | public ClientRuntimeException(String message) { 29 | super(message); 30 | } 31 | 32 | public ClientRuntimeException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/ClientState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * An enumeration used to describe the state of the MQ Light client. This is the state 23 | * machine backing the client: 24 | * MQ Light client state machine 25 | */ 26 | public enum ClientState { 27 | STARTING, STARTED, STOPPING, STOPPED, RETRYING 28 | } 29 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/CompletionListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * A listener for completion of NonBlockingClient operations. For example: 23 | *
24 |  * NonBlockingClient client = // ... initialization code
25 |  * 
26 |  * client.send("/kittens", "Hello kitty!", new CompletionListener() {
27 |  *     public void onSuccess(NonBlockingClient c,  // c == client
28 |  *                           Object ctx) {
29 |  *        // ... code for handling success of send operation
30 |  *     }
31 |  *     public void onError(NonBlockingClient c, // c == client
32 |  *                         Object ctx,
33 |  *                         ClientCheckedException exception) {
34 |  *        // ... code for handing failure of send operation - for example:
35 |  *        exception.printStackTrace();  // The reason the operation failed.
36 |  *     }
37 |  * }, null);    // This value is passed into the listener as the context argument...
38 |  * 
39 | */ 40 | public interface CompletionListener { 41 | 42 | /** 43 | * Called to indicate that the operation completed successfully. 44 | * @param client the client that the listener was registered against. 45 | * @param context an object that was supplied at the point the listener was 46 | * registered. This allows an application to correlate the 47 | * invocation of a listener with the point at which the listener 48 | * was registered. 49 | */ 50 | void onSuccess(NonBlockingClient client, T context); 51 | 52 | /** 53 | * Called to indicate that the operation failed. 54 | * @param client the client that the listener was registered against. 55 | * @param context an object that was supplied at the point the listener was 56 | * registered. This allows an application to correlate the 57 | * invocation of a listener with the point at which the listener 58 | * was registered. 59 | * @param exception an exception that indicates why the operation failed. 60 | */ 61 | void onError(NonBlockingClient client, T context, Exception exception); 62 | } 63 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/DestinationAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * An abstract adapter class for receiving destination events. The methods in this class are empty. 23 | * This class exists as convenience for creating destination listener objects. Extend this class to 24 | * create a DestinationListener object and override the methods for the events of interest. 25 | * (If you implement the DestinationListener interface, you have to define all of the methods in it. 26 | * This abstract class defines null methods for them all, so you can only have to define methods for 27 | * events you care about.) 28 | */ 29 | public abstract class DestinationAdapter implements DestinationListener { 30 | 31 | @Override 32 | public void onMessage(NonBlockingClient client, T context, Delivery delivery) {} 33 | 34 | @Override 35 | public void onMalformed(NonBlockingClient client, T context, MalformedDelivery delivery) {} 36 | 37 | @Override 38 | public void onUnsubscribed(NonBlockingClient client, T context, String topicPattern, String share, Exception error) {} 39 | } 40 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/JsonDelivery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | import com.google.gson.Gson; 22 | import com.google.gson.JsonElement; 23 | import com.google.gson.JsonParseException; 24 | import com.google.gson.JsonParser; 25 | import com.google.gson.JsonSyntaxException; 26 | 27 | /** 28 | * A sub-type of delivery that is used to represent JSON data being received 29 | * by the client. 30 | */ 31 | public interface JsonDelivery extends Delivery { 32 | 33 | /** 34 | * Deserializes the JSON data into an object of the specified class. Use the {@link JsonDelivery#getData(java.lang.reflect.Type)} 35 | * method instead if the class is of a generic type. This is equivalent to calling {@link Gson#fromJson(String, java.lang.reflect.Type)}. 36 | * 37 | * @param classOfT the class for the desired object. 38 | * @param the type of data object to return. 39 | * @return an object of type T (or null if the JSON is a representation of null). 40 | * @throws JsonSyntaxException if the JSON data cannot be deserialized into an object of type classOfT. 41 | */ 42 | T getData(Class classOfT) throws JsonSyntaxException; 43 | 44 | /** 45 | * Deserializes the JSON data into an object of the specified type. Use the {@link JsonDelivery#getData(Class)} 46 | * method instead if the class is not of a generic type. This is equivalent to calling {@link Gson#fromJson(String, java.lang.reflect.Type)}. 47 | * 48 | * @param typeOfT the type for the desired object. 49 | * @param the type of data object to return. 50 | * @return an object of type T (or null if the JSON is a representation of null). 51 | * @throws JsonSyntaxException if the JSON data cannot be deserialized into an object of type typeOfT. 52 | */ 53 | T getData(java.lang.reflect.Type typeOfT) throws JsonSyntaxException; 54 | 55 | /** 56 | * @return a {@link JsonElement} representing the deserialized JSON data. This is equivalent to calling {@link JsonParser#parse(String)}. 57 | * @throws JsonParseException if the data is not valid JSON. 58 | * @throws JsonSyntaxException if the data contains malformed JSON elements. 59 | */ 60 | JsonElement getData() throws JsonParseException; 61 | 62 | /** 63 | * @return a String representation of the JSON. This allows other parsers to be used. 64 | */ 65 | String getRawData(); 66 | } 67 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/MalformedDelivery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | public interface MalformedDelivery extends BytesDelivery { 22 | 23 | /** 24 | * Describes the reason that a message has been delivered using the onMalformed(...) 25 | * method. 26 | */ 27 | enum MalformedReason { 28 | FORMATNOMAPPING, 29 | JMSNOMAPPING, 30 | PAYLOADENCODING, 31 | PAYLOADNOTAMQP 32 | } 33 | 34 | MalformedReason getReason(); 35 | 36 | String getDescription(); 37 | 38 | String getMQMDFormat(); 39 | 40 | int getMQMDCodedCharSetId(); 41 | } 42 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/NetworkException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Used to indicate that a client has failed due to a network related problem. In this case 23 | * the client is disconnected from the MQ Light server and notified using an 24 | * instance of this exception. 25 | */ 26 | public class NetworkException extends ClientException { 27 | 28 | private static final long serialVersionUID = -1910478698106122154L; 29 | 30 | public NetworkException(String message) { 31 | super(message); 32 | } 33 | 34 | public NetworkException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/NonBlockingClientAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | import com.ibm.mqlight.api.logging.Logger; 22 | import com.ibm.mqlight.api.logging.LoggerFactory; 23 | 24 | /** 25 | * An abstract adapter class for receiving client events. The methods in this class are empty. 26 | * This class exists as convenience for creating client listener objects. Extend this class to 27 | * create a NonBlockingClientListener object and override the methods for the events of interest. 28 | * (If you implement the NonBlockingClientListener interface, you have to define all of the methods in it. 29 | * This abstract class defines null methods for them all, so you can only have to define methods for 30 | * events you care about.) 31 | */ 32 | public abstract class NonBlockingClientAdapter implements NonBlockingClientListener { 33 | 34 | private static final Logger logger = LoggerFactory.getLogger(NonBlockingClientAdapter.class); 35 | 36 | @Override 37 | public void onStarted(NonBlockingClient client, T context) {} 38 | 39 | @Override 40 | public void onStopped(NonBlockingClient client, T context, ClientException clientException) { 41 | if (clientException != null) { 42 | logger.warning("Unhandled exception in NonBlockingClientAdapter.onStopped() method :" + clientException.getMessage()); 43 | } 44 | } 45 | 46 | @Override 47 | public void onRestarted(NonBlockingClient client, T context) {} 48 | 49 | @Override 50 | public void onRetrying(NonBlockingClient client, T context, ClientException clientException) { 51 | if (clientException != null) { 52 | logger.warning("Unhandled exception in NonBlockingClientAdapter.onRetrying() method :" + clientException.getMessage()); 53 | } 54 | } 55 | 56 | @Override 57 | public void onDrain(NonBlockingClient client, T context) {} 58 | } 59 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/NotPermittedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Used to indicate that a requested operation has been rejected because the 23 | * remote end does not permit it. 24 | */ 25 | public class NotPermittedException extends ClientException { 26 | 27 | private static final long serialVersionUID = -1910478698106122154L; 28 | 29 | public NotPermittedException(String message) { 30 | super(message); 31 | } 32 | 33 | public NotPermittedException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/Promise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Represents a promise that the recipient of an instance of this object will 23 | * perform an operation and then complete the promise by invoking 24 | * one of the set functions. 25 | * 26 | * @param the type of object passed back when the promise is completed 27 | * successfully via the {@link Promise#setSuccess(Object)} method. 28 | */ 29 | public interface Promise { 30 | 31 | /** 32 | * Called to indicate that the related operation failed in some way. 33 | * @param exception an indication of why the operation failed. 34 | * @throws IllegalStateException if the promise has already been completed. 35 | */ 36 | void setFailure(Exception exception) throws IllegalStateException; 37 | 38 | /** 39 | * Called to indicate that the related operation succeeded. 40 | * @param result an object that represents the result of the operation. 41 | * This can be passed back to the class that issued the promise. 42 | * @throws IllegalStateException if the promise has already been completed. 43 | */ 44 | void setSuccess(T result) throws IllegalStateException; 45 | 46 | /** 47 | * @return true if the promise has been completed (by either the 48 | * {@link Promise#setSuccess(Object)} or the {@link Promise#setFailure(Exception)} 49 | * method being invoked). 50 | */ 51 | boolean isComplete(); 52 | } 53 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/QOS.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * An enumeration that describes the quality of service used to transfer message 23 | * data between the client and the MQ Light server. For more details about qualities of 24 | * service - please see https://developer.ibm.com/messaging/mq-light/docs/qos/ 25 | */ 26 | public enum QOS { 27 | /** 28 | * Attempt to deliver the message at most once. With this quality of service messages 29 | * may not be delivered, but they will never be delivered more than once. 30 | */ 31 | AT_MOST_ONCE, 32 | 33 | /** 34 | * Attempt to deliver the message at least once. With this quality of service messages 35 | * may be delivered more than once, but they will never not be delivered. 36 | */ 37 | AT_LEAST_ONCE 38 | } 39 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/ReplacedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Used to indicate that the client has been replaced by another instance of itself. This behaviour 23 | * occurs when a client connects using the same client ID as an already connected client. In this case 24 | * the already connected client is disconnected from the MQ Light server and notified using an 25 | * instance of this exception. 26 | */ 27 | public class ReplacedException extends ClientException { 28 | private static final long serialVersionUID = -6033481693545964064L; 29 | 30 | public ReplacedException(String message) { 31 | super(message); 32 | } 33 | 34 | public ReplacedException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/SecurityException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * Used to indicate that a client has failed due to a security related problem. In this case 23 | * the client is disconnected from the MQ Light server and notified using an 24 | * instance of this exception. 25 | */ 26 | public class SecurityException extends ClientException { 27 | private static final long serialVersionUID = -2062256960236598587L; 28 | 29 | public SecurityException(String message) { 30 | super(message); 31 | } 32 | 33 | public SecurityException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/StartingException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * A type of {@link StateException} to indicate that the client is currently starting when a request to stop was made. 23 | */ 24 | public class StartingException extends StateException { 25 | 26 | private static final long serialVersionUID = 4396568269984986166L; 27 | 28 | public StartingException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/StateException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * This exception is thrown to indicate that the client is not in the correct state 23 | * to perform the requested operation. Examples include: 24 | *
    25 | *
  • Attempting to send, subscribe or unsubscribe while the client is in stopped or 26 | * stopping state.
  • 27 | *
  • Attempting to subscribe to a destination to which the client is already subscribed.
  • 28 | *
  • Attempting to unsubscribe from a destination to which the client is not already 29 | * subscribed.
  • 30 | *
31 | */ 32 | public class StateException extends ClientRuntimeException { 33 | 34 | private static final long serialVersionUID = -8951433512053398231L; 35 | 36 | public StateException(String message) { 37 | super(message); 38 | } 39 | 40 | public StateException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/StoppedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * A type of {@link StateException} to indicate that the client is in the stopping or stopped state which is not appropriate 23 | * to perform the requested operation. This can occur whilst attempting to send, subscribe or unsubscribe. 24 | */ 25 | public class StoppedException extends StateException { 26 | 27 | private static final long serialVersionUID = -8951433512053398231L; 28 | 29 | public StoppedException(String message) { 30 | super(message); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/StringDelivery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * A sub-type of delivery that is used to represent textual data being received 23 | * by the client. 24 | */ 25 | public interface StringDelivery extends Delivery { 26 | 27 | /** 28 | * @return a String object containing the textual data. 29 | */ 30 | String getData(); 31 | } 32 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/SubscribedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * A type of {@link StateException} to indicate that the client is attempting to subscribe to a destination for which the client is already subscribed. 23 | */ 24 | public class SubscribedException extends StateException { 25 | 26 | private static final long serialVersionUID = 2792420197537041736L; 27 | 28 | public SubscribedException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/UnsubscribedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | /** 22 | * A type of {@link StateException} to indicate that the client is attempting to unsubscribe from a destination for which the client is not already subscribed. 23 | */ 24 | public class UnsubscribedException extends StateException { 25 | 26 | private static final long serialVersionUID = 2198833574106117937L; 27 | 28 | public UnsubscribedException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/callback/CallbackService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.callback; 20 | 21 | import com.ibm.mqlight.api.NonBlockingClient; 22 | import com.ibm.mqlight.api.Promise; 23 | 24 | /** 25 | * Plug point for callback executing implementations. The implementation used for an 26 | * instance of the client can be specified using the 27 | * {@link NonBlockingClient#create(com.ibm.mqlight.api.endpoint.EndpointService, com.ibm.mqlight.api.callback.CallbackService, com.ibm.mqlight.api.network.NetworkService, com.ibm.mqlight.api.timer.TimerService, com.google.gson.GsonBuilder, com.ibm.mqlight.api.ClientOptions, com.ibm.mqlight.api.NonBlockingClientListener, Object)} 28 | * method. 29 | */ 30 | public interface CallbackService { 31 | 32 | /** 33 | * Run the specified runnable. This method will be invoked each time the client 34 | * needs to call back into application code. 35 | * 36 | * @param runnable the Runnable to run. 37 | * @param orderingCtx an object that is used to order the execution of runnables. 38 | * The implementor of this interface must ensure that if two 39 | * calls specify the same orderingCtx object they 40 | * are executed in the order the calls are made. Two calls that 41 | * specify different values for the orderingCtx 42 | * parameter can have their runnables executed in any order. 43 | * @param promise a promise which is to be completed when the runnable has finished 44 | * executing. 45 | */ 46 | void run(Runnable runnable, Object orderingCtx, Promise promise); 47 | } 48 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/doc-files/sm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqlight/java-mqlight/8283484569ce61733bb976e7a9542373ca29c272/mqlight/src/main/java/com/ibm/mqlight/api/doc-files/sm.gif -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/endpoint/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.endpoint; 20 | 21 | import java.net.URI; 22 | 23 | import com.ibm.mqlight.api.ClientOptions.SSLOptions; 24 | 25 | /** 26 | * Bundles information that the client uses when establishing connections 27 | * to the system hosting the MQ Light server. 28 | */ 29 | public interface Endpoint { 30 | 31 | /** 32 | * @return the host name of the system to connect to. 33 | */ 34 | String getHost(); 35 | 36 | /** 37 | * @return the port number to connect to. 38 | */ 39 | int getPort(); 40 | 41 | /** 42 | * @return indicates whether an SSL/TLS protected connection should 43 | * be used. 44 | */ 45 | boolean useSsl(); 46 | 47 | /** 48 | * @return the user name to use as part of a SASL PLAIN flow used to 49 | * authenticate the client. If this value is null 50 | * then the SASL ANONYMOUS mechanism will be used instead. 51 | */ 52 | String getUser(); 53 | 54 | /** 55 | * @return the password to use as part of a SASL PLAIN flow used to 56 | * authenticate the client. 57 | */ 58 | String getPassword(); 59 | 60 | /** 61 | * @return the maximum idle period between activity (frames) on the 62 | * connection that the client desires from this endpoint. 63 | */ 64 | int getIdleTimeout(); 65 | 66 | /** 67 | * @return The URI for this endpoint, derived from the host and port, 68 | * and taking into account whether or not SSL/TLS is enabled. 69 | */ 70 | URI getURI(); 71 | 72 | /** 73 | * @return the required SSL/TLS options. 74 | */ 75 | SSLOptions getSSLOptions(); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/endpoint/EndpointPromise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.endpoint; 20 | 21 | import com.ibm.mqlight.api.Promise; 22 | 23 | /** 24 | * A promise that is used to indicate the outcome of an endpoint lookup 25 | * operation. The inherited {@link Promise#setSuccess(Object)} 26 | * method is used when the lookup operation is successful and returns an 27 | * {@link Endpoint}. The inherited {@link Promise#setFailure(Exception)} 28 | * method is used when the lookup operation fails and the client should 29 | * transition into stopped state. The {@link EndpointPromise#setWait(long)} 30 | * method is used to indicate that the client should wait for a period of 31 | * time before making more endpoint lookup requests 32 | */ 33 | public interface EndpointPromise extends Promise{ 34 | 35 | /** 36 | * Completes the promise and indicates to the client that it should 37 | * wait for a period of time before querying the endpoint service again. 38 | * 39 | * @param delay a wait time in milliseconds. 40 | * @throws IllegalStateException if this method is invoked when the promise 41 | * has already been completed. 42 | */ 43 | void setWait(long delay) throws IllegalStateException; 44 | } 45 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/endpoint/EndpointService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.endpoint; 20 | 21 | import com.ibm.mqlight.api.NonBlockingClient; 22 | import com.ibm.mqlight.api.Promise; 23 | 24 | /** 25 | * Plug point for endpoint lookup implementations. The implementation used for an 26 | * instance of the client can be specified using the 27 | * {@link NonBlockingClient#create(com.ibm.mqlight.api.endpoint.EndpointService, com.ibm.mqlight.api.callback.CallbackService, com.ibm.mqlight.api.network.NetworkService, com.ibm.mqlight.api.timer.TimerService, com.google.gson.GsonBuilder, com.ibm.mqlight.api.ClientOptions, com.ibm.mqlight.api.NonBlockingClientListener, Object)} 28 | * method. 29 | */ 30 | public interface EndpointService { 31 | 32 | /** 33 | * Called by the client each time it needs to make a decision about which endpoint 34 | * to attempt a connection to. 35 | *

36 | * When the operation completes the promise (supplied as an argument) is used to 37 | * notify the client of the outcome. If an endpoint is available it will be 38 | * supplied to the {@link Promise#setSuccess(Object)} method. If no 39 | * endpoints are currently available, the client can be advised to wait for a 40 | * period of time before calling this method again using the {@link EndpointPromise#setWait(long)} 41 | * method. Indicating failure by calling the {@link EndpointPromise#setFailure(Exception)} 42 | * will cause the client to transition into stopped state. 43 | * 44 | * @param promise a promise that is to be completed when the endpoint service has 45 | * completed the lookup request. 46 | */ 47 | void lookup(EndpointPromise promise); 48 | 49 | /** 50 | * Called by the client when it has successfully established a connection to one of 51 | * the endpoints returned by this service. This allows the endpoint service to 52 | * optimise the order in which it returns endpoints (for example to implement an 53 | * algorithm that always returns the most recently successful endpoints first). 54 | * 55 | * @param endpoint the endpoint to which a connection has successfully being established. 56 | */ 57 | void onSuccess(Endpoint endpoint); 58 | } 59 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/BytesDeliveryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import java.nio.ByteBuffer; 22 | import java.util.Map; 23 | 24 | import com.ibm.mqlight.api.BytesDelivery; 25 | import com.ibm.mqlight.api.QOS; 26 | import com.ibm.mqlight.api.impl.engine.DeliveryRequest; 27 | 28 | class BytesDeliveryImpl extends DeliveryImpl implements BytesDelivery { 29 | 30 | private final ByteBuffer data; 31 | 32 | protected BytesDeliveryImpl(NonBlockingClientImpl client, QOS qos, String shareName, String topic, 33 | String topicPattern, long ttl, ByteBuffer data, Map properties, DeliveryRequest req) { 34 | super(client, qos, shareName, topic, topicPattern, ttl, properties, req); 35 | this.data = data; 36 | } 37 | 38 | @Override 39 | public Type getType() { 40 | return Type.BYTES; 41 | } 42 | 43 | @Override 44 | public ByteBuffer getData() { 45 | return data; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/Component.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | public interface Component { 22 | void tell(Message message, Component self); 23 | } 24 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/ComponentImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import java.util.LinkedList; 22 | 23 | import com.ibm.mqlight.api.logging.FFDCProbeId; 24 | import com.ibm.mqlight.api.logging.Logger; 25 | import com.ibm.mqlight.api.logging.LoggerFactory; 26 | 27 | public abstract class ComponentImpl implements Component { 28 | 29 | private static final Logger logger = LoggerFactory.getLogger(ComponentImpl.class); 30 | 31 | public static final ComponentImpl NOBODY = new ComponentImpl() { 32 | public void tell(Message message, Component self) {} 33 | @Override protected void onReceive(Message message) { 34 | logger.data(this, "tell", message); 35 | } 36 | }; 37 | 38 | private final LinkedList queue = new LinkedList<>(); 39 | private boolean scheduled = false; 40 | protected final Object componentMonitor = new Object(); 41 | 42 | public void tell(Message message, Component self) { 43 | final String methodName = "tell"; 44 | logger.entry(this, methodName, message, self); 45 | 46 | message.setSender(self); 47 | boolean execute; 48 | synchronized(queue) { 49 | queue.addLast(message); 50 | execute = !scheduled; 51 | if (execute) scheduled = true; 52 | } 53 | if (execute) deliverMessages(); 54 | 55 | logger.exit(this, methodName); 56 | } 57 | 58 | private void deliverMessages() { 59 | final String methodName = "deliverMessages"; 60 | logger.entry(this, methodName); 61 | 62 | while(true) { 63 | Message message = null; 64 | synchronized(queue) { 65 | if (queue.isEmpty()) { 66 | scheduled = false; 67 | break; 68 | } 69 | else message = queue.removeFirst(); 70 | } 71 | synchronized(componentMonitor) { 72 | try { 73 | onReceive(message); 74 | } catch (Throwable e) { 75 | logger.ffdc(methodName, FFDCProbeId.PROBE_001, e); 76 | } 77 | } 78 | } 79 | 80 | logger.exit(this, methodName); 81 | } 82 | 83 | protected abstract void onReceive(Message message); 84 | } 85 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/FSMActions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | public interface FSMActions { 22 | 23 | void startTimer(); 24 | 25 | void openConnection(); 26 | 27 | void closeConnection(); 28 | 29 | void cancelTimer(); 30 | 31 | void requestEndpoint(); 32 | 33 | /** 34 | * This action remakes the client's subscriptions. 35 | *

36 | * The action is invoked whenever a connection is recovered. 37 | */ 38 | void remakeInboundLinks(); 39 | 40 | void blessEndpoint(); 41 | 42 | /** 43 | * This action performs the cleanup operations such as flushing/failing any pending sends or subscribes. 44 | *

45 | * The action can be invoked when a client is stopping. 46 | */ 47 | void cleanup(); 48 | 49 | void failPendingStops(); 50 | 51 | void succeedPendingStops(); 52 | 53 | void failPendingStarts(); 54 | 55 | void succeedPendingStarts(); 56 | 57 | // All of these relate to external state machine transitions 58 | void eventStarting(); 59 | void eventUserStopping(); 60 | void eventSystemStopping(); 61 | void eventStopped(); 62 | void eventStarted(); 63 | void eventRetrying(); 64 | void eventRestarted(); 65 | 66 | /** 67 | * This action breaks any pending sends and subscription requests from the client 68 | *

69 | * The action is invoked whenever a network error occurs and the client is not stopping. 70 | */ 71 | void breakInboundLinks(); 72 | 73 | void processQueuedActions(); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/InternalSend.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | 23 | import com.ibm.mqlight.api.QOS; 24 | import com.ibm.mqlight.api.logging.Logger; 25 | import com.ibm.mqlight.api.logging.LoggerFactory; 26 | 27 | class InternalSend extends Message implements QueueableWork { 28 | 29 | private static final Logger logger = LoggerFactory.getLogger(InternalSend.class); 30 | 31 | final String topic; 32 | final QOS qos; 33 | final ByteBuf buf; 34 | final int length; 35 | final boolean retainLink; 36 | final CompletionFuture future; 37 | 38 | InternalSend(NonBlockingClientImpl client, String topic, QOS qos, ByteBuf buf, int length, boolean retainLink) { 39 | final String methodName = ""; 40 | logger.entry(this, methodName, client, topic, qos, buf, length); 41 | 42 | this.future = new CompletionFuture<>(client); 43 | this.topic = topic; 44 | this.qos = qos; 45 | this.buf = buf; 46 | this.length = length; 47 | this.retainLink = retainLink; 48 | 49 | logger.exit(this, methodName); 50 | } 51 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/InternalStart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import com.ibm.mqlight.api.logging.Logger; 22 | import com.ibm.mqlight.api.logging.LoggerFactory; 23 | 24 | class InternalStart extends Message { 25 | 26 | private static final Logger logger = LoggerFactory.getLogger(InternalStart.class); 27 | 28 | final CompletionFuture future; 29 | InternalStart(NonBlockingClientImpl client) { 30 | final String methodName = ""; 31 | logger.entry(this, methodName, client); 32 | 33 | future = new CompletionFuture<>(client); 34 | 35 | logger.exit(this, methodName); 36 | } 37 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/InternalStop.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import com.ibm.mqlight.api.logging.Logger; 22 | import com.ibm.mqlight.api.logging.LoggerFactory; 23 | 24 | class InternalStop extends Message { 25 | 26 | private static final Logger logger = LoggerFactory.getLogger(InternalStop.class); 27 | 28 | final CompletionFuture future; 29 | InternalStop(NonBlockingClientImpl client) { 30 | final String methodName = ""; 31 | logger.entry(this, methodName, client); 32 | 33 | future = new CompletionFuture<>(client); 34 | 35 | logger.exit(this, methodName); 36 | } 37 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/InternalSubscribe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import com.google.gson.GsonBuilder; 22 | import com.ibm.mqlight.api.DestinationListener; 23 | import com.ibm.mqlight.api.QOS; 24 | import com.ibm.mqlight.api.logging.Logger; 25 | import com.ibm.mqlight.api.logging.LoggerFactory; 26 | 27 | class InternalSubscribe extends Message implements QueueableWork { 28 | 29 | private static final Logger logger = LoggerFactory.getLogger(InternalSubscribe.class); 30 | 31 | final CompletionFuture future; 32 | final SubscriptionTopic topic; 33 | final QOS qos; 34 | final int credit; 35 | final boolean autoConfirm; 36 | final long ttl; 37 | final DestinationListenerWrapper destListener; 38 | 39 | InternalSubscribe(NonBlockingClientImpl client, SubscriptionTopic topic, QOS qos, int credit, boolean autoConfirm, long ttl, 40 | GsonBuilder gsonBuilder, DestinationListener destListener, T context) { 41 | final String methodName = ""; 42 | logger.entry(this, methodName, client, topic, qos, credit, autoConfirm, ttl, gsonBuilder, destListener, context); 43 | 44 | future = new CompletionFuture<>(client); 45 | this.topic = topic; 46 | this.qos = qos; 47 | this.credit = credit; 48 | this.autoConfirm = autoConfirm; 49 | this.ttl = ttl; 50 | this.destListener = new DestinationListenerWrapper<>(client, gsonBuilder, destListener, context); 51 | 52 | logger.exit(this, methodName); 53 | } 54 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/InternalUnsubscribe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import com.ibm.mqlight.api.logging.Logger; 22 | import com.ibm.mqlight.api.logging.LoggerFactory; 23 | 24 | class InternalUnsubscribe extends Message implements QueueableWork { 25 | 26 | private static final Logger logger = LoggerFactory.getLogger(InternalUnsubscribe.class); 27 | 28 | final CompletionFuture future; 29 | final String topicPattern; 30 | final String share; 31 | final boolean zeroTtl; 32 | InternalUnsubscribe(NonBlockingClientImpl client, String topicPattern, String share, boolean zeroTtl) { 33 | final String methodName = ""; 34 | logger.entry(this, methodName, client, topicPattern, share, zeroTtl); 35 | 36 | future = new CompletionFuture<>(client); 37 | this.topicPattern = topicPattern; 38 | this.share = share; 39 | this.zeroTtl = zeroTtl; 40 | 41 | logger.exit(this, methodName); 42 | } 43 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/Message.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | public abstract class Message { 22 | 23 | private Component sender = null; 24 | 25 | public Component getSender() { 26 | return sender; 27 | } 28 | 29 | protected void setSender(Component sender) { 30 | this.sender = sender; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/NonBlockingClientState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import java.util.EnumSet; 22 | 23 | enum NonBlockingClientState { 24 | Retrying1A, Retrying1B, Retrying1C, 25 | Retrying2A, Retrying2B, Retrying2C, Retrying2D, 26 | Started, 27 | StartingA, StartingB, 28 | Stopped, 29 | StoppingA, StoppingB, StoppingC, StoppingD, 30 | StoppingR1A, StoppingR1B, StoppingR1C, StoppingR1D, StoppingR1E, StoppingR1F, 31 | StoppingR2A, StoppingR2B, StoppingR2C, StoppingR2D, StoppingR2E, StoppingR2F, StoppingR2G, StoppingR2H, 32 | StoppingSA, StoppingSB, StoppingSC, StoppingSD; 33 | 34 | public static final EnumSet acceptingWorkStates = EnumSet.of(Started); 35 | public static final EnumSet queueingWorkStates = 36 | EnumSet.of(Retrying1A, Retrying1B, Retrying1C, Retrying2A, Retrying2B, Retrying2C, Retrying2D, StartingA, StartingB); 37 | public static final EnumSet rejectingWorkStates = 38 | EnumSet.of(Stopped, StoppingA, StoppingB, StoppingC, StoppingD, StoppingR1A, StoppingR1B, StoppingR1C, StoppingR1D, StoppingR1E, StoppingR1F, 39 | StoppingR2A, StoppingR2B, StoppingR2C, StoppingR2D, StoppingR2E, StoppingR2F, StoppingR2G, StoppingR2H, StoppingSA, StoppingSB, StoppingSC, StoppingSD); 40 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/NonBlockingClientTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | enum NonBlockingClientTrigger { 22 | START, STOP, 23 | CLOSE_RESP, 24 | EP_RESP_OK, EP_RESP_EXHAUSTED, EP_RESP_FATAL, 25 | NETWORK_ERROR, 26 | INBOUND_WORK_COMPLETE, 27 | OPEN_RESP_OK, OPEN_RESP_FATAL, OPEN_RESP_RETRY, 28 | TIMER_RESP_POP, TIMER_RESP_CANCEL, 29 | SUBS_REMADE, 30 | REPLACED 31 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/QueueableWork.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | // Tagging interface - used to create a generic type for any (internal) request to the 22 | // non-blocking client that should be queued up and replayed after connectivity is broken / re-established. 23 | public interface QueueableWork { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/StringDeliveryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import java.util.Map; 22 | 23 | import com.ibm.mqlight.api.QOS; 24 | import com.ibm.mqlight.api.StringDelivery; 25 | import com.ibm.mqlight.api.impl.engine.DeliveryRequest; 26 | import com.ibm.mqlight.api.logging.Logger; 27 | import com.ibm.mqlight.api.logging.LoggerFactory; 28 | 29 | class StringDeliveryImpl extends DeliveryImpl implements StringDelivery { 30 | 31 | private static final Logger logger = LoggerFactory.getLogger(StringDeliveryImpl.class); 32 | 33 | private final String data; 34 | 35 | protected StringDeliveryImpl(NonBlockingClientImpl client, QOS qos, String share, String topic, 36 | String topicPattern, long ttl, String data, Map properties, DeliveryRequest deliveryRequest) { 37 | super(client, qos, share, topic, topicPattern, ttl, properties, deliveryRequest); 38 | final String methodName = ""; 39 | logger.entry(this, methodName, client, qos, share, topic, topicPattern, ttl, data, properties, deliveryRequest); 40 | 41 | this.data = data; 42 | 43 | logger.exit(this, methodName); 44 | } 45 | 46 | @Override 47 | public Type getType() { 48 | return Type.STRING; 49 | } 50 | 51 | @Override 52 | public String getData() { 53 | return data; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/callback/CallbackExceptionNotification.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class CallbackExceptionNotification extends Message { 24 | public final Exception exception; 25 | public CallbackExceptionNotification(Exception exception) { 26 | this.exception = exception; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/callback/CallbackPromiseImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | import com.ibm.mqlight.api.Promise; 24 | import com.ibm.mqlight.api.impl.Component; 25 | import com.ibm.mqlight.api.impl.ComponentImpl; 26 | import com.ibm.mqlight.api.logging.Logger; 27 | import com.ibm.mqlight.api.logging.LoggerFactory; 28 | 29 | public class CallbackPromiseImpl implements Promise { 30 | 31 | private static final Logger logger = LoggerFactory.getLogger(CallbackPromiseImpl.class); 32 | 33 | private final AtomicBoolean complete = new AtomicBoolean(false); 34 | private final Component component; 35 | private final boolean ignoreSuccess; 36 | 37 | public CallbackPromiseImpl(Component component, boolean ignoreSuccess) { 38 | final String methodName = ""; 39 | logger.entry(this, methodName, component, ignoreSuccess); 40 | 41 | this.component = component; 42 | this.ignoreSuccess = ignoreSuccess; 43 | 44 | logger.exit(this, methodName); 45 | } 46 | 47 | @Override 48 | public boolean isComplete() { 49 | return complete.get(); 50 | } 51 | 52 | @Override 53 | public void setFailure(Exception exception) throws IllegalStateException { 54 | final String methodName = "setFailure"; 55 | logger.entry(this, methodName, exception); 56 | 57 | if (complete.getAndSet(true)) { 58 | final IllegalStateException ex = new IllegalStateException("Promise already completed"); 59 | logger.throwing(this, methodName, ex); 60 | throw ex; 61 | } 62 | component.tell(new CallbackExceptionNotification(exception), component); 63 | 64 | logger.exit(this, methodName); 65 | } 66 | 67 | @Override 68 | public void setSuccess(Void result) throws IllegalStateException { 69 | final String methodName = "setSuccess"; 70 | logger.entry(this, methodName, result); 71 | 72 | if (complete.getAndSet(true)) { 73 | final IllegalStateException ex = new IllegalStateException("Promise already completed"); 74 | logger.throwing(this, methodName, ex); 75 | throw ex; 76 | } else { 77 | if (!ignoreSuccess) { 78 | component.tell(new FlushResponse(), ComponentImpl.NOBODY); 79 | } 80 | } 81 | 82 | logger.exit(this, methodName); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/callback/FlushResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class FlushResponse extends Message { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/callback/SameThreadCallbackService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import com.ibm.mqlight.api.ClientException; 22 | import com.ibm.mqlight.api.Promise; 23 | import com.ibm.mqlight.api.callback.CallbackService; 24 | 25 | public class SameThreadCallbackService implements CallbackService { 26 | 27 | @Override 28 | public void run(Runnable runnable, Object orderingCtx, Promise promise) { 29 | try { 30 | runnable.run(); 31 | promise.setSuccess(null); 32 | } catch(Exception e) { 33 | promise.setFailure(new ClientException("Application code threw an exception from within a callback. See linked exception for more details.", e)); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/endpoint/EndpointResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.endpoint; 20 | 21 | import com.ibm.mqlight.api.ClientException; 22 | import com.ibm.mqlight.api.endpoint.Endpoint; 23 | import com.ibm.mqlight.api.impl.Message; 24 | 25 | public class EndpointResponse extends Message { 26 | 27 | public final Endpoint endpoint; 28 | public final ClientException exception; 29 | 30 | public EndpointResponse(Endpoint endpoint, ClientException exception) { 31 | this.endpoint = endpoint; 32 | this.exception = exception; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/endpoint/EndpointServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.endpoint; 20 | 21 | import com.ibm.mqlight.api.endpoint.EndpointService; 22 | import com.ibm.mqlight.api.logging.Logger; 23 | import com.ibm.mqlight.api.logging.LoggerFactory; 24 | 25 | public abstract class EndpointServiceImpl implements EndpointService { 26 | 27 | private static final Logger logger = LoggerFactory.getLogger(EndpointServiceImpl.class); 28 | 29 | protected long calculateDelay(int retryCount) { 30 | final String methodName = "calculateDelay"; 31 | logger.entry(this, methodName, retryCount); 32 | 33 | double upperBound = 1 << (retryCount < 9 ? retryCount : 8); 34 | double lowerBound = 0.75 * upperBound; 35 | double jitter = Math.random() * (0.25 * upperBound); 36 | double interval = Math.min(60000, (lowerBound + jitter) * 1000); 37 | 38 | long result = Math.round(interval); 39 | 40 | logger.exit(this, methodName, result); 41 | 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/endpoint/ExhaustedResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.endpoint; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class ExhaustedResponse extends Message { 24 | public final long delay; 25 | public ExhaustedResponse(long delay) { 26 | this.delay = delay; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/endpoint/SingleEndpointService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.endpoint; 20 | 21 | import com.ibm.mqlight.api.ClientOptions.SSLOptions; 22 | import com.ibm.mqlight.api.endpoint.Endpoint; 23 | import com.ibm.mqlight.api.endpoint.EndpointPromise; 24 | import com.ibm.mqlight.api.impl.LogbackLogging; 25 | import com.ibm.mqlight.api.logging.Logger; 26 | import com.ibm.mqlight.api.logging.LoggerFactory; 27 | 28 | public class SingleEndpointService extends EndpointServiceImpl { 29 | 30 | private static final Logger logger = LoggerFactory.getLogger(SingleEndpointService.class); 31 | 32 | static { 33 | LogbackLogging.setup(); 34 | } 35 | 36 | private final Endpoint endpoint; 37 | boolean exhausted = false; 38 | int retryCount = 0; 39 | 40 | @Override 41 | public void lookup(EndpointPromise future) { 42 | final String methodName = "lookup"; 43 | logger.entry(this, methodName, future); 44 | 45 | if (exhausted) { 46 | exhausted = false; 47 | future.setWait(calculateDelay(retryCount++)); 48 | } else { 49 | exhausted = true; 50 | future.setSuccess(endpoint); 51 | } 52 | 53 | logger.exit(this, methodName); 54 | } 55 | 56 | @Override 57 | public void onSuccess(Endpoint endpoint) { 58 | final String methodName = "onSuccess"; 59 | logger.entry(this, methodName, endpoint); 60 | 61 | exhausted = false; 62 | retryCount = 0; 63 | 64 | logger.exit(this, methodName); 65 | } 66 | 67 | public SingleEndpointService(String uri, String user, String password, SSLOptions sslOptions) { 68 | final String methodName = ""; 69 | logger.entry(this, methodName, uri, user, "******", sslOptions); 70 | 71 | endpoint = new EndpointImpl(uri, user, password, sslOptions); 72 | 73 | logger.exit(this, methodName); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/CloseRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class CloseRequest extends Message { 24 | public final EngineConnection connection; 25 | 26 | public CloseRequest(EngineConnection connection) { 27 | this.connection = connection; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/CloseResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class CloseResponse extends Message { 24 | public final CloseRequest request; 25 | public CloseResponse(CloseRequest request) { 26 | this.request = request; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/DeliveryRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import org.apache.qpid.proton.engine.Connection; 22 | import org.apache.qpid.proton.engine.Delivery; 23 | 24 | import com.ibm.mqlight.api.QOS; 25 | import com.ibm.mqlight.api.impl.Message; 26 | 27 | // Note: this is slightly unusual in that it is sent from the Engine to the 28 | // component that issued the subscribe (rather than most messages in 29 | // this package which are sent from some Component to the Engine component) 30 | public class DeliveryRequest extends Message { 31 | 32 | public byte[] buf; 33 | public final QOS qos; 34 | public final String topicPattern; 35 | protected final Delivery delivery; 36 | protected final Connection protonConnection; 37 | 38 | public DeliveryRequest(byte[] buf, QOS qos, String topicPattern, Delivery delivery, Connection protonConnection) { 39 | this.buf = buf; 40 | this.qos = qos; 41 | this.topicPattern = topicPattern; 42 | this.delivery = delivery; 43 | this.protonConnection = protonConnection; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/DeliveryResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | // Note: this is unusual for a response message in that it flows to the engine. 24 | public class DeliveryResponse extends Message { 25 | public final DeliveryRequest request; 26 | public DeliveryResponse(DeliveryRequest request) { 27 | this.request = request; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/DisconnectNotification.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class DisconnectNotification extends Message { 24 | 25 | public final EngineConnection connection; 26 | public final Throwable error; 27 | 28 | public DisconnectNotification(EngineConnection connection, Throwable error) { 29 | this.connection = connection; 30 | this.error = error; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/DrainNotification.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class DrainNotification extends Message { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/OpenRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.endpoint.Endpoint; 22 | import com.ibm.mqlight.api.impl.Message; 23 | 24 | public class OpenRequest extends Message { 25 | 26 | public final Endpoint endpoint; 27 | public final String clientId; 28 | 29 | public OpenRequest(Endpoint endpoint, String clientId) { 30 | this.endpoint = endpoint; 31 | this.clientId = clientId; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/OpenResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.ClientException; 22 | import com.ibm.mqlight.api.impl.Message; 23 | 24 | public class OpenResponse extends Message { 25 | 26 | public final OpenRequest request; 27 | public final EngineConnection connection; 28 | public final ClientException exception; 29 | 30 | public OpenResponse(OpenRequest request, EngineConnection connection) { 31 | this.request = request; 32 | this.connection = connection; 33 | this.exception = null; 34 | } 35 | 36 | public OpenResponse(OpenRequest request, ClientException exception) { 37 | this.request = request; 38 | this.connection = null; 39 | this.exception = exception; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/SendRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | 23 | import com.ibm.mqlight.api.QOS; 24 | import com.ibm.mqlight.api.impl.Message; 25 | 26 | public class SendRequest extends Message { 27 | protected final EngineConnection connection; 28 | protected final String topic; 29 | protected final ByteBuf buf; 30 | protected final int length; 31 | protected final QOS qos; 32 | protected final boolean retainLink; 33 | 34 | public SendRequest(EngineConnection connection, String topic, ByteBuf buf, int length, QOS qos, boolean retainLink) { 35 | this.connection = connection; 36 | this.topic = topic; 37 | this.buf = buf; 38 | this.length = length; 39 | this.qos = qos; 40 | this.retainLink = retainLink; 41 | } 42 | 43 | public void releaseBuf() { 44 | buf.release(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/SendResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class SendResponse extends Message { 24 | 25 | public final SendRequest request; 26 | public final Exception cause; 27 | public SendResponse(SendRequest request, Exception cause) { 28 | this.request = request; 29 | this.cause = cause; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/SubscribeRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.QOS; 22 | import com.ibm.mqlight.api.impl.Message; 23 | import com.ibm.mqlight.api.impl.SubscriptionTopic; 24 | 25 | public class SubscribeRequest extends Message { 26 | public final EngineConnection connection; 27 | public final SubscriptionTopic topic; 28 | public final QOS qos; 29 | public final int initialCredit; 30 | public final long ttl; 31 | 32 | public SubscribeRequest(EngineConnection connection, SubscriptionTopic topic, QOS qos, int initialCredit, long ttl) { 33 | this.connection = connection; 34 | this.topic = topic; 35 | this.qos = qos; 36 | this.initialCredit = initialCredit; 37 | this.ttl = ttl; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/SubscribeResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | import com.ibm.mqlight.api.impl.SubscriptionTopic; 23 | 24 | public class SubscribeResponse extends Message { 25 | public final EngineConnection connection; 26 | public final SubscriptionTopic topic; 27 | public final Exception error; 28 | public SubscribeResponse(EngineConnection connection, SubscriptionTopic topic, Exception error) { 29 | this.connection = connection; 30 | this.topic = topic; 31 | this.error = error; 32 | } 33 | public SubscribeResponse(EngineConnection connection, SubscriptionTopic topic) { 34 | this(connection, topic, null); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/UnsubscribeRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | import com.ibm.mqlight.api.impl.SubscriptionTopic; 23 | 24 | public class UnsubscribeRequest extends Message { 25 | public final EngineConnection connection; 26 | public final SubscriptionTopic topic; 27 | public final boolean zeroTtl; 28 | public UnsubscribeRequest(EngineConnection connection, SubscriptionTopic topic, boolean zeroTtl) { 29 | this.connection = connection; 30 | this.topic = topic; 31 | this.zeroTtl = zeroTtl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/engine/UnsubscribeResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.engine; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | import com.ibm.mqlight.api.impl.SubscriptionTopic; 23 | 24 | public class UnsubscribeResponse extends Message { 25 | public final EngineConnection connection; 26 | public final SubscriptionTopic topic; 27 | public final Exception error; 28 | public UnsubscribeResponse(EngineConnection connection, SubscriptionTopic topic, Exception error) { 29 | this.connection = connection; 30 | this.topic = topic; 31 | this.error = error; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/LogMarker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging; 21 | 22 | import org.slf4j.Marker; 23 | import org.slf4j.MarkerFactory; 24 | 25 | /** 26 | * Defines the various SLF4J Markers used by MQ Light logging. 27 | */ 28 | public enum LogMarker { 29 | INFO ("info"), 30 | WARNING ("warn"), 31 | ERROR ("error"), 32 | FFDC ("ffdc"), 33 | ENTRY ("entry"), 34 | EXIT ("exit"), 35 | DATA ("data"), 36 | THROWING ("throwing"); 37 | 38 | private final Marker marker; 39 | 40 | LogMarker(String markerLabel) { 41 | marker = MarkerFactory.getMarker(markerLabel); 42 | } 43 | 44 | public Marker getValue() { 45 | return marker; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/LoggerFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging; 21 | 22 | import com.ibm.mqlight.api.logging.Logger; 23 | import com.ibm.mqlight.api.logging.LoggerFactory; 24 | 25 | /** 26 | * Factory implementation to obtain a {@link Logger} implementation. 27 | */ 28 | class LoggerFactoryImpl extends LoggerFactory { 29 | 30 | /** 31 | * Obtains a {@link Logger} implementation for the specified class. 32 | * 33 | * @param clazz Class to be associated with the logger instance. 34 | * @return {@link Logger} instance for trace and information logging. 35 | */ 36 | protected Logger getLoggerImpl(Class clazz) { 37 | return new LoggerImpl(clazz); 38 | } 39 | 40 | @Override 41 | protected Logger getLoggerImpl(org.slf4j.Logger logger) { 42 | return new LoggerImpl(logger); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/Version.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging; 21 | 22 | import java.io.IOException; 23 | import java.net.URL; 24 | import java.net.URLClassLoader; 25 | import java.util.Map.Entry; 26 | import java.util.jar.Attributes; 27 | import java.util.jar.Manifest; 28 | 29 | import com.ibm.mqlight.api.logging.Logger; 30 | import com.ibm.mqlight.api.logging.LoggerFactory; 31 | 32 | /** 33 | * Provides information about the product version. 34 | */ 35 | public class Version { 36 | 37 | private static final Class cclass = Version.class; 38 | 39 | private static final Logger logger = LoggerFactory.getLogger(cclass); 40 | 41 | /** 42 | * obtains the MQ Light version information from the manifest. 43 | * 44 | * @return The MQ Light version. 45 | */ 46 | public static String getVersion() { 47 | String version = "unknown"; 48 | final URLClassLoader cl = (URLClassLoader)cclass.getClassLoader(); 49 | try { 50 | final URL url = cl.findResource("META-INF/MANIFEST.MF"); 51 | final Manifest manifest = new Manifest(url.openStream()); 52 | for (Entry entry : manifest.getMainAttributes().entrySet()) { 53 | final Attributes.Name key = (Attributes.Name)entry.getKey(); 54 | if(Attributes.Name.IMPLEMENTATION_VERSION.equals(key)) { 55 | version = (String)entry.getValue(); 56 | } 57 | } 58 | } catch (IOException e) { 59 | logger.error("Unable to determine the product version due to error", e); 60 | } 61 | return version; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/ClientIdConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import java.util.Map; 23 | 24 | import ch.qos.logback.classic.pattern.ClassicConverter; 25 | import ch.qos.logback.classic.spi.ILoggingEvent; 26 | 27 | import com.ibm.mqlight.api.logging.Logger; 28 | 29 | /** 30 | * A logback converter to support a client id customer conversion specifier. 31 | *

32 | * Note that the client id is obtained from the MDC (Mapped Diagnostic Context), which can be set from the {@link Logger#setClientId(String)} method. 33 | */ 34 | public class ClientIdConverter extends ClassicConverter { 35 | 36 | @Override 37 | public String convert(ILoggingEvent event) { 38 | final Map mdc = event.getMDCPropertyMap(); 39 | final String clientId = mdc == null ? null : mdc.get(Logger.CLIENTID_KEY); 40 | return clientId == null ? "*" : clientId; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/IndentConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import org.slf4j.Marker; 26 | 27 | import com.ibm.mqlight.api.impl.logging.LogMarker; 28 | 29 | import ch.qos.logback.classic.pattern.ClassicConverter; 30 | import ch.qos.logback.classic.spi.ILoggingEvent; 31 | 32 | /** 33 | * A logback converter to support an indent customer conversion specifier. 34 | *

35 | * Note that the {@link #convert(ILoggingEvent)} method simply returns a {@link String} with a single character based on the passed event's marker (if the marker is not recognised 36 | * or no marker is present, a {@link String} with a single space character is returned). 37 | *

38 | * Actual indenting has not been implemented as it will affect trace performance. Using a suitable Boss trace filter it will be possible for Boss trace to format and indent as 39 | * required anyway, hence indentation is not required by the service team. 40 | */ 41 | public class IndentConverter extends ClassicConverter { 42 | 43 | private static Map markerMap = new HashMap<>(); 44 | static { 45 | markerMap.put(LogMarker.INFO.getValue(), "i"); 46 | markerMap.put(LogMarker.WARNING.getValue(), "w"); 47 | markerMap.put(LogMarker.ERROR.getValue(), "e"); 48 | markerMap.put(LogMarker.FFDC.getValue(), "f"); 49 | 50 | markerMap.put(LogMarker.ENTRY.getValue(), "{"); 51 | markerMap.put(LogMarker.EXIT.getValue(), "}"); 52 | markerMap.put(LogMarker.DATA.getValue(), "d"); 53 | markerMap.put(LogMarker.THROWING.getValue(), "!"); 54 | } 55 | 56 | @Override 57 | public String convert(ILoggingEvent event) { 58 | final Marker marker = event.getMarker(); 59 | String indent = null; 60 | if (marker != null) indent = markerMap.get(marker); 61 | if (indent == null) indent = " "; 62 | return indent; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/LevelConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import org.slf4j.Marker; 23 | 24 | import ch.qos.logback.classic.pattern.ClassicConverter; 25 | import ch.qos.logback.classic.spi.ILoggingEvent; 26 | 27 | /** 28 | * A logback converter to support a level, based on the marker, customer conversion specifier. 29 | *

30 | * When a passed event contains a matrker, the {@link #convert(ILoggingEvent)} method simply returns a {@link String} with text for the marker, otherwise the a {@link String} for the event's level is returned. 31 | */ 32 | public class LevelConverter extends ClassicConverter { 33 | 34 | @Override 35 | public String convert(ILoggingEvent event) { 36 | final Marker marker = event.getMarker(); 37 | return marker == null ? (event.getLevel() == null ? "" : event.getLevel().toString()) : marker.getName(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/LogFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import ch.qos.logback.classic.spi.ILoggingEvent; 23 | import ch.qos.logback.core.filter.Filter; 24 | import ch.qos.logback.core.spi.FilterReply; 25 | 26 | /** 27 | * A logback filter for selecting MQ Light events that are not trace. 28 | */ 29 | public class LogFilter extends Filter { 30 | 31 | @Override 32 | public FilterReply decide(ILoggingEvent event) { 33 | if (!TraceFilter.traceMarkerMap.containsKey(event.getMarker())) { 34 | return FilterReply.ACCEPT; 35 | } else { 36 | return FilterReply.DENY; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/ObjectIdConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * A logback converter to support an object id customer conversion specifier. 22 | *

23 | * Note that this assumes that whenever the event has one of the trace markers (defined in {@link TraceFilter}) then the first argument for the event specifies the object id, or 24 | * null implying no object id is appropriate. 25 | */ 26 | package com.ibm.mqlight.api.impl.logging.logback; 27 | 28 | import org.slf4j.Marker; 29 | 30 | import ch.qos.logback.classic.pattern.ClassicConverter; 31 | import ch.qos.logback.classic.spi.ILoggingEvent; 32 | 33 | public class ObjectIdConverter extends ClassicConverter { 34 | 35 | @Override 36 | public String convert(ILoggingEvent event) { 37 | final String result; 38 | final Marker marker = event.getMarker(); 39 | if (TraceFilter.traceMarkerMap.containsKey(marker)) { 40 | final Object args[] = event.getArgumentArray(); 41 | if (args != null && args.length > 0) { 42 | Object obj = event.getArgumentArray()[0]; 43 | result = obj == null ? "static" : "@"+Integer.toHexString(System.identityHashCode(obj)); 44 | } else { 45 | result = ""; 46 | } 47 | } else { 48 | result = ""; 49 | } 50 | return result; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/PIDConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import ch.qos.logback.classic.pattern.ClassicConverter; 23 | import ch.qos.logback.classic.spi.ILoggingEvent; 24 | 25 | /** 26 | * A logback converter to support a process id customer conversion specifier. 27 | */ 28 | public class PIDConverter extends ClassicConverter { 29 | 30 | static final String pid; 31 | static { 32 | final String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); 33 | pid = processName.split("@")[0]; 34 | } 35 | 36 | @Override 37 | public String convert(ILoggingEvent event) { 38 | return pid; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/TIDConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import ch.qos.logback.classic.pattern.ClassicConverter; 23 | import ch.qos.logback.classic.spi.ILoggingEvent; 24 | 25 | /** 26 | * A logback converter to support a thread id customer conversion specifier. 27 | */ 28 | public class TIDConverter extends ClassicConverter { 29 | 30 | @Override 31 | public String convert(ILoggingEvent event) { 32 | return String.format("%04d", Thread.currentThread().getId()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/logging/logback/TraceFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging.logback; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import org.slf4j.Marker; 26 | 27 | import com.ibm.mqlight.api.impl.logging.LogMarker; 28 | 29 | import ch.qos.logback.classic.spi.ILoggingEvent; 30 | import ch.qos.logback.core.filter.Filter; 31 | import ch.qos.logback.core.spi.FilterReply; 32 | 33 | /** 34 | * A logback filter for selecting MQ Light trace type events. These are events that have been marked as entry, exit, data or throwing. 35 | */ 36 | public class TraceFilter extends Filter { 37 | 38 | static Map traceMarkerMap = new HashMap<>(); 39 | static { 40 | traceMarkerMap.put(LogMarker.ENTRY.getValue(), "{"); 41 | traceMarkerMap.put(LogMarker.EXIT.getValue(), "}"); 42 | traceMarkerMap.put(LogMarker.DATA.getValue(), "d"); 43 | traceMarkerMap.put(LogMarker.THROWING.getValue(), "!"); 44 | } 45 | 46 | @Override 47 | public FilterReply decide(ILoggingEvent event) { 48 | if (traceMarkerMap.containsKey(event.getMarker())) { 49 | return FilterReply.ACCEPT; 50 | } else { 51 | return FilterReply.DENY; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/network/ConnectResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import com.ibm.mqlight.api.ClientException; 22 | import com.ibm.mqlight.api.impl.Message; 23 | import com.ibm.mqlight.api.network.NetworkChannel; 24 | 25 | public class ConnectResponse extends Message { 26 | public final NetworkChannel channel; 27 | public final ClientException exception; 28 | public final Object context; 29 | 30 | public ConnectResponse(NetworkChannel channel, ClientException exception, Object context) { 31 | this.channel = channel; 32 | this.exception = exception; 33 | this.context = context; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/network/ConnectionError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | import com.ibm.mqlight.api.network.NetworkChannel; 23 | 24 | public class ConnectionError extends Message { 25 | 26 | public final NetworkChannel channel; 27 | public final Throwable cause; 28 | 29 | public ConnectionError(NetworkChannel channel, Throwable cause) { 30 | this.channel = channel; 31 | this.cause = cause; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/network/DataRead.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | 23 | import com.ibm.mqlight.api.impl.Message; 24 | import com.ibm.mqlight.api.network.NetworkChannel; 25 | 26 | public class DataRead extends Message { 27 | public final NetworkChannel channel; 28 | public final ByteBuf buffer; 29 | public DataRead(NetworkChannel channel, ByteBuf buffer) { 30 | this.channel = channel; 31 | this.buffer = buffer; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/network/DisconnectResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class DisconnectResponse extends Message { 24 | public final Object context; 25 | public DisconnectResponse(Object context) { 26 | this.context = context; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/network/NetworkListenerImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | 23 | import java.io.IOException; 24 | 25 | import com.ibm.mqlight.api.impl.Component; 26 | import com.ibm.mqlight.api.impl.ComponentImpl; 27 | import com.ibm.mqlight.api.network.NetworkChannel; 28 | import com.ibm.mqlight.api.network.NetworkListener; 29 | 30 | public class NetworkListenerImpl implements NetworkListener { 31 | 32 | private final Component component; 33 | 34 | public NetworkListenerImpl(Component component) { 35 | this.component = component; 36 | } 37 | 38 | @Override 39 | public void onRead(NetworkChannel channel, ByteBuf buffer) { 40 | component.tell(new DataRead(channel, buffer), ComponentImpl.NOBODY); 41 | } 42 | 43 | @Override 44 | public void onClose(NetworkChannel channel) { 45 | component.tell(new ConnectionError(channel, new IOException("Network connection closed by server")), ComponentImpl.NOBODY); 46 | } 47 | 48 | @Override 49 | public void onError(NetworkChannel channel, Exception exception) { 50 | component.tell(new ConnectionError(channel, exception), ComponentImpl.NOBODY); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/network/WriteResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class WriteResponse extends Message { 24 | public final Object context; 25 | public final long amount; 26 | public final boolean drained; 27 | public WriteResponse(Object context, long amount, boolean drained) { 28 | this.context = context; 29 | this.amount = amount; 30 | this.drained = drained; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/timer/CancelResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.timer; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class CancelResponse extends Message { 24 | 25 | public final TimerPromiseImpl promise; 26 | public CancelResponse(TimerPromiseImpl promise) { 27 | this.promise = promise; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/timer/PopResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.timer; 20 | 21 | import com.ibm.mqlight.api.impl.Message; 22 | 23 | public class PopResponse extends Message { 24 | 25 | public final TimerPromiseImpl promise; 26 | protected PopResponse(TimerPromiseImpl promise) { 27 | this.promise = promise; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/impl/timer/TimerPromiseImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.timer; 20 | 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | import com.ibm.mqlight.api.Promise; 24 | import com.ibm.mqlight.api.impl.Component; 25 | import com.ibm.mqlight.api.logging.Logger; 26 | import com.ibm.mqlight.api.logging.LoggerFactory; 27 | 28 | public class TimerPromiseImpl implements Promise { 29 | 30 | private static final Logger logger = LoggerFactory.getLogger(TimerPromiseImpl.class); 31 | 32 | private final Component component; 33 | private final Object context; 34 | private final AtomicBoolean complete = new AtomicBoolean(false); 35 | 36 | public TimerPromiseImpl(Component component, Object context) { 37 | final String methodName = ""; 38 | logger.entry(this, methodName, component, context); 39 | 40 | this.component = component; 41 | this.context = context; 42 | 43 | logger.exit(this, methodName); 44 | } 45 | 46 | @Override 47 | public void setFailure(Exception exception) throws IllegalStateException { 48 | final String methodName = "setFailure"; 49 | logger.entry(this, methodName, exception); 50 | 51 | if (complete.getAndSet(true)) { 52 | final IllegalStateException ex = new IllegalStateException("Promise already completed"); 53 | logger.throwing(this, methodName, ex); 54 | throw ex; 55 | } else { 56 | component.tell(new CancelResponse(this), component); 57 | } 58 | 59 | logger.exit(this, methodName); 60 | } 61 | 62 | @Override 63 | public void setSuccess(Void result) throws IllegalStateException { 64 | final String methodName = "setSuccess"; 65 | logger.entry(this, methodName, result); 66 | 67 | if (complete.getAndSet(true)) { 68 | final IllegalStateException exception = new IllegalStateException("Promise already completed"); 69 | logger.throwing(this, methodName, exception); 70 | throw exception; 71 | } else { 72 | component.tell(new PopResponse(this), component); 73 | } 74 | 75 | logger.exit(this, methodName); 76 | } 77 | 78 | @Override 79 | public boolean isComplete() { 80 | return complete.get(); 81 | } 82 | 83 | public Object getContext() { 84 | return context; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/logging/FFDCProbeId.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.logging; 21 | 22 | /** 23 | * Probe identifiers for First Failure Data Capture. 24 | */ 25 | public enum FFDCProbeId { 26 | PROBE_001("FFDC_001"), 27 | PROBE_002("FFDC_002"), 28 | PROBE_003("FFDC_003"), 29 | PROBE_004("FFDC_004"), 30 | PROBE_005("FFDC_005"), 31 | PROBE_006("FFDC_006"), 32 | PROBE_007("FFDC_007"), 33 | PROBE_008("FFDC_008"), 34 | PROBE_009("FFDC_009"), 35 | PROBE_010("FFDC_010"), 36 | PROBE_011("FFDC_011"), 37 | PROBE_012("FFDC_012"), 38 | PROBE_013("FFDC_013"), 39 | PROBE_014("FFDC_014"), 40 | PROBE_015("FFDC_015"), 41 | PROBE_016("FFDC_016"), 42 | PROBE_017("FFDC_017"), 43 | PROBE_018("FFDC_018"), 44 | PROBE_019("FFDC_019"), 45 | PROBE_020("FFDC_020"), 46 | PROBE_021("FFDC_021"), 47 | PROBE_022("FFDC_022"), 48 | PROBE_023("FFDC_023"), 49 | PROBE_024("FFDC_024"), 50 | PROBE_025("FFDC_025"), 51 | PROBE_026("FFDC_026"), 52 | PROBE_027("FFDC_027"), 53 | PROBE_028("FFDC_028"), 54 | PROBE_029("FFDC_029"), 55 | PROBE_030("FFDC_030"), 56 | PROBE_031("FFDC_031"), 57 | PROBE_032("FFDC_032"), 58 | PROBE_033("FFDC_033"), 59 | PROBE_034("FFDC_034"), 60 | PROBE_035("FFDC_035"), 61 | PROBE_036("FFDC_036"), 62 | PROBE_037("FFDC_037"), 63 | PROBE_038("FFDC_038"), 64 | PROBE_039("FFDC_039"), 65 | PROBE_040("FFDC_040"), 66 | PROBE_041("FFDC_041"), 67 | PROBE_042("FFDC_042"), 68 | PROBE_043("FFDC_043"), 69 | PROBE_044("FFDC_044"), 70 | PROBE_045("FFDC_045"), 71 | PROBE_046("FFDC_046"), 72 | PROBE_047("FFDC_047"), 73 | PROBE_048("FFDC_048"), 74 | PROBE_049("FFDC_049"); 75 | 76 | private final String id; 77 | 78 | FFDCProbeId(String id) { 79 | this.id = id; 80 | } 81 | 82 | public String toString() { 83 | return id; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/network/NetworkChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.network; 20 | 21 | import java.nio.ByteBuffer; 22 | 23 | import com.ibm.mqlight.api.Promise; 24 | 25 | /** 26 | * Represents an open network connection 27 | */ 28 | public interface NetworkChannel { 29 | 30 | /** 31 | * Close the connection. 32 | * @param promise a promise which is to be completed when the connection is closed. 33 | */ 34 | void close(Promise promise); 35 | 36 | /** 37 | * Write data to the network connection. 38 | * @param buffer contains the data to write. 39 | * @param promise a promise which is to be completed when the data is written. 40 | */ 41 | void write(ByteBuffer buffer, Promise promise); 42 | 43 | /** 44 | * Allows an arbitrary object to be associated with this channel object. 45 | * @param context the arbitrary object. 46 | */ 47 | void setContext(Object context); 48 | 49 | /** 50 | * Retrieves the value set using {@link NetworkChannel#setContext(Object)}. 51 | * Returns null if no value has yet been set. 52 | * @return the context object (if any) set using {@link NetworkChannel#setContext(Object)} 53 | */ 54 | Object getContext(); 55 | } 56 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/network/NetworkListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.network; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | 23 | /** 24 | * A listener for events that occur on a particular network channel. 25 | */ 26 | public interface NetworkListener { 27 | 28 | /** 29 | * Called when data is read from the network. 30 | * @param channel identifies which network connection the data was 31 | * read from. 32 | * @param buffer contains the data that has been read. The buffer belongs 33 | * to the implementation of this method - and will not be 34 | * altered by the implementation of {@link NetworkService} once 35 | * this method has been invoked. 36 | *

37 | * Once the buffer is finished with the {@link ByteBuf#release()} 38 | * method must be called to return the buffer to the pool, otherwise 39 | * a memory leak will eventually be reported by the 40 | * {@link io.netty.util.ResourceLeakDetector}. 41 | */ 42 | void onRead(NetworkChannel channel, ByteBuf buffer); 43 | 44 | /** 45 | * Called when the network connection is closed at the remote end. 46 | * @param channel identifies which network connections was closed. 47 | */ 48 | void onClose(NetworkChannel channel); 49 | 50 | /** 51 | * Called when an error occurs on the network connection - for example because 52 | * the process at the remote end of the connection abruptly ends. 53 | * @param channel identifies which network connection the error relates to. 54 | * @param exception an exception relating to the error condition. 55 | */ 56 | void onError(NetworkChannel channel, Exception exception); 57 | } 58 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/network/NetworkService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.network; 20 | 21 | import com.ibm.mqlight.api.NonBlockingClient; 22 | import com.ibm.mqlight.api.Promise; 23 | import com.ibm.mqlight.api.endpoint.Endpoint; 24 | 25 | /** 26 | * Plug point for network implementations. The implementation used for an 27 | * instance of the client can be specified using the 28 | * {@link NonBlockingClient#create(com.ibm.mqlight.api.endpoint.EndpointService, com.ibm.mqlight.api.callback.CallbackService, com.ibm.mqlight.api.network.NetworkService, com.ibm.mqlight.api.timer.TimerService, com.google.gson.GsonBuilder, com.ibm.mqlight.api.ClientOptions, com.ibm.mqlight.api.NonBlockingClientListener, Object)} 29 | * method. 30 | */ 31 | public interface NetworkService { 32 | 33 | /** 34 | * Establish a network connection. 35 | * @param endpoint provides information about the host, port, etc. to establish the network 36 | * connection to. 37 | * @param listener a listener that will be notified of network connection related events. 38 | * The listener will only be used if the network connection is successfully 39 | * established. 40 | * @param promise a promise to complete when the outcome of the network connection attempt is 41 | * established. If the network connection is successfully established then the 42 | * {@link Promise#setSuccess(Object)} is passed an implementation of 43 | * {@link NetworkChannel} that can be used to send data over the network connection. 44 | */ 45 | void connect(Endpoint endpoint, NetworkListener listener, Promise promise); 46 | } 47 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/resources/mqlight-logback.xml: -------------------------------------------------------------------------------- 1 | 21 | 22 | 24 | 25 | 27 | 28 | 30 | 31 | 33 | 34 | 36 | 37 | 39 | 40 | 42 | 43 | 45 | 46 | 48 | 49 | -------------------------------------------------------------------------------- /mqlight/src/main/java/com/ibm/mqlight/api/timer/TimerService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.timer; 20 | 21 | import com.ibm.mqlight.api.NonBlockingClient; 22 | import com.ibm.mqlight.api.Promise; 23 | 24 | /** 25 | * Plug point for timer implementations. The implementation used for an 26 | * instance of the client can be specified using the 27 | * {@link NonBlockingClient#create(com.ibm.mqlight.api.endpoint.EndpointService, com.ibm.mqlight.api.callback.CallbackService, com.ibm.mqlight.api.network.NetworkService, TimerService, com.google.gson.GsonBuilder, com.ibm.mqlight.api.ClientOptions, com.ibm.mqlight.api.NonBlockingClientListener, Object)} 28 | * method. 29 | */ 30 | public interface TimerService { 31 | 32 | /** 33 | * Schedules a timer that will "pop" at some point in the future. When the 34 | * timer "pops" the promise, specified as a parameter, must be completed successfully 35 | * by calling the {@link Promise#setSuccess(Object)} method. Timers are "single shot" 36 | * as the promise can only be completed once. 37 | *

38 | * The implementation cannot block the calling thread - and so must employ some scheme 39 | * that uses another thread to complete the promise. 40 | * 41 | * @param delay a delay in milliseconds 42 | * @param promise a promise object to be completed after the delay period 43 | */ 44 | void schedule(long delay, Promise promise); 45 | 46 | /** 47 | * Cancels a previously scheduled promise (e.g. one that has previously been passed to 48 | * the {@link TimerService#schedule(long, Promise)} method. If the cancel operation is 49 | * successful then the promise's {@link Promise#setFailure(Exception)} method will be 50 | * invoked. 51 | *

52 | * Once a promise has been scheduled, using the {@link TimerService#schedule(long, Promise)} 53 | * it will always be completed - even if it is cancelled as a result of this method 54 | * being invoked. 55 | *

56 | * If this method is invoked on a promise which has already completed, it should have no 57 | * effect. 58 | * 59 | * @param promise the promise to cancel 60 | */ 61 | void cancel(Promise promise); 62 | } 63 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/TestClientOptions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | import junit.framework.AssertionFailedError; 22 | 23 | import org.junit.Test; 24 | 25 | public class TestClientOptions { 26 | 27 | @Test 28 | public void clientIdLength() { 29 | final StringBuilder sb = new StringBuilder(); 30 | for (int i=0; i<256; i++) sb.append(i % 10); 31 | final String maxLengthClientId = sb.toString(); 32 | sb.append("a"); 33 | final String overLengthClientId = sb.toString(); 34 | ClientOptions.builder().setId(maxLengthClientId).build(); // 256-char 35 | ClientOptions.builder().setId("0").build(); 36 | ClientOptions.builder().setId(null).build(); 37 | 38 | try { 39 | ClientOptions.builder().setId("").build(); 40 | throw new AssertionFailedError("Expected a zero-length ID to be rejected"); 41 | } catch(IllegalArgumentException e) { 42 | // Expected. 43 | } 44 | 45 | try { 46 | ClientOptions.builder().setId(overLengthClientId).build(); 47 | throw new AssertionFailedError("Expected a 257 character length ID to be rejected"); 48 | } catch(IllegalArgumentException e) { 49 | // Expected 50 | } 51 | } 52 | 53 | @Test 54 | public void clientIdValidChars() { 55 | ClientOptions.builder().setId("abcdefghijklmnopqrstuvwxyz").build(); 56 | ClientOptions.builder().setId("ABCDEFGHIJKLMNOPQRSTUVWXYZ").build(); 57 | ClientOptions.builder().setId("0123456789").build(); 58 | ClientOptions.builder().setId("%./_").build(); 59 | try { 60 | ClientOptions.builder().setId("badid!").build(); 61 | throw new AssertionFailedError("ID should have been rejected"); 62 | } catch(IllegalArgumentException e) { 63 | // Expected. 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/TestNonBlockingClientAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api; 21 | 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import java.io.ByteArrayOutputStream; 25 | import java.io.PrintStream; 26 | import java.util.UUID; 27 | 28 | import org.junit.Test; 29 | 30 | import com.ibm.mqlight.api.impl.logging.logback.LogbackLoggingImpl; 31 | 32 | public class TestNonBlockingClientAdapter { 33 | 34 | // Test that the default implementation of NonBlockingClientAdapter 35 | // logs a warning if either the onStopped or onRetrying methods care 36 | // called with a non-null exception argument. 37 | @Test 38 | public void defaultImplWarnsOnExceptions() { 39 | 40 | String expectedRetryingExceptionMessage = UUID.randomUUID().toString(); 41 | String expectedStoppedExceptionMessage = UUID.randomUUID().toString(); 42 | NonBlockingClientAdapter adapter = 43 | new NonBlockingClientAdapter() { 44 | }; 45 | ClientException retryingException = 46 | new ClientException(expectedRetryingExceptionMessage); 47 | ClientException stoppedException = 48 | new ClientException(expectedStoppedExceptionMessage); 49 | 50 | LogbackLoggingImpl.stop(); 51 | 52 | final ByteArrayOutputStream baos = new ByteArrayOutputStream(); 53 | final PrintStream ps = new PrintStream(baos, true); 54 | final PrintStream savedOut = System.out; 55 | try { 56 | System.setOut(ps); 57 | LogbackLoggingImpl.setDefaultRequiredMQLightLogLevel("warn"); 58 | LogbackLoggingImpl.setup(); 59 | adapter.onRetrying(null, null, retryingException); 60 | adapter.onStopped(null, null, stoppedException); 61 | System.out.flush(); 62 | String traceData = baos.toString(); 63 | 64 | System.out.println(traceData); 65 | assertTrue("missing retry exception message", 66 | traceData.contains(expectedRetryingExceptionMessage)); 67 | assertTrue("missing stopped exception message", 68 | traceData.contains(expectedStoppedExceptionMessage)); 69 | } finally { 70 | LogbackLoggingImpl.stop(); 71 | System.setOut(savedOut); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/TestSendOptions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api; 20 | 21 | import junit.framework.AssertionFailedError; 22 | 23 | import static org.junit.Assert.*; 24 | import org.junit.Test; 25 | 26 | public class TestSendOptions { 27 | 28 | @Test 29 | public void defaults() { 30 | SendOptions opts = SendOptions.builder().build(); 31 | assertEquals(QOS.AT_MOST_ONCE, opts.getQos()); 32 | assertEquals(0, opts.getTtl()); 33 | } 34 | 35 | @Test 36 | public void getSet() { 37 | SendOptions opts = SendOptions.builder().setQos(QOS.AT_LEAST_ONCE).setTtl(8).build(); 38 | assertEquals(QOS.AT_LEAST_ONCE, opts.getQos()); 39 | assertEquals(8, opts.getTtl()); 40 | } 41 | 42 | @Test 43 | public void qosValues() { 44 | SendOptions.builder().setQos(QOS.AT_LEAST_ONCE); 45 | SendOptions.builder().setQos(QOS.AT_MOST_ONCE); 46 | try { 47 | SendOptions.builder().setQos(null); 48 | throw new AssertionFailedError("null should have been rejected"); 49 | } catch(IllegalArgumentException e) { 50 | // Expected 51 | } 52 | } 53 | 54 | @Test 55 | public void ttlValues() { 56 | SendOptions.builder().setTtl(1); 57 | SendOptions.builder().setTtl(4294967295L); 58 | 59 | try { 60 | SendOptions.builder().setTtl(0); 61 | throw new AssertionFailedError("0 should have been rejected"); 62 | } catch(IllegalArgumentException e) { 63 | // Expected 64 | } 65 | 66 | try { 67 | SendOptions.builder().setTtl(4294967296L); 68 | throw new AssertionFailedError("4294967296L should have been rejected"); 69 | } catch(IllegalArgumentException e) { 70 | // Expected 71 | } 72 | } 73 | 74 | @Test 75 | public void retainLinkValues() { 76 | SendOptions defaultRetainLinkOpts = SendOptions.builder().build(); 77 | assertEquals(true, defaultRetainLinkOpts.getRetainLink()); 78 | 79 | SendOptions explicitRetainLinkFalseOpts = SendOptions.builder().setRetainLink(false).build(); 80 | assertEquals(false, explicitRetainLinkFalseOpts.getRetainLink()); 81 | 82 | SendOptions explicitRetainLinkTrueOpts = SendOptions.builder().setRetainLink(true).build(); 83 | assertEquals(true, explicitRetainLinkTrueOpts.getRetainLink()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/MockComponent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl; 20 | 21 | import java.util.LinkedList; 22 | 23 | import junit.framework.AssertionFailedError; 24 | 25 | import com.ibm.mqlight.api.impl.ComponentImpl; 26 | import com.ibm.mqlight.api.impl.Message; 27 | 28 | public class MockComponent extends ComponentImpl { 29 | private LinkedList messages = new LinkedList<>(); 30 | 31 | @Override protected void onReceive(Message message) { 32 | throw new AssertionFailedError("onReceive should not have been called"); 33 | } 34 | 35 | @Override public synchronized void tell(Message message, Component self) { 36 | messages.add(message); 37 | } 38 | 39 | public synchronized LinkedList getMessages() { 40 | return messages; 41 | } 42 | } -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/callback/MockCallbackPromise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertFalse; 23 | 24 | import com.ibm.mqlight.api.Promise; 25 | 26 | public class MockCallbackPromise implements Promise { 27 | 28 | protected enum Method { NONE, SUCCESS, FAILURE } 29 | private final Method expectedMethod; 30 | private final boolean checkMethod; 31 | private boolean done; 32 | private boolean success; 33 | private Exception exception; 34 | 35 | protected MockCallbackPromise(Method expectedMethod) { 36 | this(expectedMethod, true); 37 | } 38 | 39 | protected MockCallbackPromise(Method expectedMethod, boolean checkMethod) { 40 | this.expectedMethod = expectedMethod; 41 | this.checkMethod = checkMethod; 42 | } 43 | 44 | @Override public synchronized boolean isComplete() { 45 | return done; 46 | } 47 | 48 | public synchronized boolean waitForComplete(int timeout) throws InterruptedException { 49 | if (done) return true; 50 | else { 51 | wait(timeout); 52 | return done; 53 | } 54 | } 55 | 56 | public synchronized boolean isSuccessful() { 57 | return success; 58 | } 59 | 60 | @Override public synchronized void setSuccess(Void x) { 61 | if (checkMethod) { 62 | assertEquals("didn't expect setSuccess to be called", expectedMethod, Method.SUCCESS); 63 | assertFalse("didn't expect setSuccess to be called on a completed future", done); 64 | } 65 | done = true; 66 | success = true; 67 | notifyAll(); 68 | } 69 | 70 | @Override 71 | public synchronized void setFailure(Exception exception) { 72 | if (checkMethod) { 73 | assertEquals("didn't expect setFailure to be called", expectedMethod, Method.FAILURE); 74 | assertFalse("didn't expect setSuccess to be called on a completed future", done); 75 | } 76 | this.exception = exception; 77 | done = true; 78 | notifyAll(); 79 | } 80 | 81 | protected synchronized Exception getException() { 82 | return exception; 83 | } 84 | 85 | protected Method getExpectedMethod() { 86 | return expectedMethod; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/callback/TestCallbackPromiseImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import junit.framework.AssertionFailedError; 22 | import static org.junit.Assert.*; 23 | 24 | import org.junit.Test; 25 | 26 | import com.ibm.mqlight.api.impl.MockComponent; 27 | 28 | public class TestCallbackPromiseImpl { 29 | 30 | @Test 31 | public void success() { 32 | MockComponent mockComponent = new MockComponent(); 33 | CallbackPromiseImpl promise = new CallbackPromiseImpl(mockComponent, false); 34 | 35 | assertFalse("Promise should not have been created in a completed stata", promise.isComplete()); 36 | promise.setSuccess(null); 37 | 38 | assertTrue("Promise should have been marked complete", promise.isComplete()); 39 | assertEquals("Expected a single message to have been delivered to the component", 1, mockComponent.getMessages().size()); 40 | assertTrue("Message should have been of type FlushResponse", mockComponent.getMessages().get(0) instanceof FlushResponse); 41 | 42 | try { 43 | promise.setSuccess(null); 44 | throw new AssertionFailedError("Should not have been able to complete a promise twice (calling setSuccess)"); 45 | } catch(IllegalStateException e) { 46 | // Expected code path 47 | } 48 | 49 | try { 50 | promise.setFailure(null); 51 | throw new AssertionFailedError("Should not have been able to complete a promise twice (calling setFailure)"); 52 | } catch(IllegalStateException e) { 53 | // Expected code path 54 | } 55 | } 56 | 57 | public void ignoreSuccess() { 58 | MockComponent mockComponent = new MockComponent(); 59 | CallbackPromiseImpl promise = new CallbackPromiseImpl(mockComponent, true); 60 | promise.setSuccess(null); 61 | assertEquals("Expected no messages to have been delivered to the component", 0, mockComponent.getMessages().size()); 62 | } 63 | 64 | @Test 65 | public void failure() { 66 | MockComponent mockComponent = new MockComponent(); 67 | CallbackPromiseImpl promise = new CallbackPromiseImpl(mockComponent, false); 68 | 69 | promise.setFailure(new Exception()); 70 | assertTrue("Promise should have been marked complete", promise.isComplete()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/callback/TestSameThreadCallbackService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.callback; 20 | 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | import static org.junit.Assert.*; 24 | import org.junit.Test; 25 | 26 | import com.ibm.mqlight.api.callback.CallbackService; 27 | import com.ibm.mqlight.api.impl.callback.MockCallbackPromise.Method; 28 | 29 | public class TestSameThreadCallbackService { 30 | 31 | @Test 32 | public void successfulCallback() { 33 | CallbackService cbs = new SameThreadCallbackService(); 34 | MockCallbackPromise future = new MockCallbackPromise(Method.SUCCESS); 35 | final AtomicBoolean run = new AtomicBoolean(false); 36 | cbs.run(new Runnable() { 37 | public void run() { 38 | run.set(true); 39 | } 40 | }, new Object(), future); 41 | 42 | assertTrue("Runnable should have been run!", run.get()); 43 | } 44 | 45 | @Test 46 | public void exceptionThrownInCallback() { 47 | CallbackService cbs = new SameThreadCallbackService(); 48 | MockCallbackPromise future = new MockCallbackPromise(Method.FAILURE); 49 | final RuntimeException exception = new RuntimeException(); 50 | cbs.run(new Runnable() { 51 | public void run() { 52 | throw exception; 53 | } 54 | }, new Object(), future); 55 | 56 | assertSame("Exception should have been thrown from run()!", exception, future.getException().getCause()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/endpoint/MockEndpointPromise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.endpoint; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.junit.Assert.assertFalse; 23 | 24 | import com.ibm.mqlight.api.endpoint.Endpoint; 25 | import com.ibm.mqlight.api.endpoint.EndpointPromise; 26 | 27 | class MockEndpointPromise implements EndpointPromise { 28 | 29 | protected enum Method { NONE, SUCCESS, WAIT, FAILURE } 30 | private final MockEndpointPromise.Method expectedMethod; 31 | private Endpoint actualEndpoint; 32 | long actualDelay; 33 | private boolean done; 34 | 35 | protected MockEndpointPromise(MockEndpointPromise.Method expectedMethod) { 36 | this.expectedMethod = expectedMethod; 37 | } 38 | 39 | @Override public synchronized boolean isComplete() { 40 | return done; 41 | } 42 | 43 | @Override public synchronized void setSuccess(Endpoint endpoint) { 44 | assertEquals("didn't expect setSuccess to be called", expectedMethod, Method.SUCCESS); 45 | assertFalse("didn't expect setSuccess to be called on a completed future", done); 46 | done = true; 47 | actualEndpoint = endpoint; 48 | } 49 | 50 | @Override 51 | public synchronized void setWait(long delay) { 52 | assertEquals("didn't expect setWait to be called", expectedMethod, Method.WAIT); 53 | assertFalse("didn't expect setSuccess to be called on a completed future", done); 54 | done = true; 55 | actualDelay = delay; 56 | } 57 | 58 | @Override 59 | public synchronized void setFailure(Exception exception) { 60 | assertEquals("didn't expect setFailure to be called", expectedMethod, Method.FAILURE); 61 | assertFalse("didn't expect setSuccess to be called on a completed future", done); 62 | done = true; 63 | } 64 | 65 | protected Endpoint getEndoint() { return actualEndpoint; } 66 | protected long getDelay() { return actualDelay; } 67 | } -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/logging/MockEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.ibm.mqlight.api.impl.logging; 21 | 22 | import java.util.Arrays; 23 | 24 | import org.slf4j.Marker; 25 | 26 | public class MockEvent { 27 | public final String type; 28 | public final Marker marker; 29 | public final String message; 30 | public final Object [] args; 31 | public final Throwable throwable; 32 | 33 | public MockEvent(String type, Marker marker, String message, Object... args) { 34 | this.type = type; 35 | this.marker = marker; 36 | this.message = message; 37 | if (args.length > 1 && args[1] instanceof Throwable) { 38 | this.throwable = (Throwable)args[1]; 39 | this.args = new Object[args.length-1]; 40 | this.args[0] = args[0]; 41 | for (int i=2; i { 28 | 29 | private final AtomicBoolean done = new AtomicBoolean(false); 30 | 31 | @Override 32 | public boolean isComplete() { 33 | return done.get(); 34 | } 35 | 36 | @Override 37 | public void setSuccess(Void x) { 38 | done.set(true); 39 | } 40 | 41 | @Override 42 | public void setFailure(Exception exception) { 43 | done.set(true); 44 | throw new AssertionFailedError("setFailed should never be called!"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/network/MockNetworkConnectPromise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import java.util.LinkedList; 22 | 23 | import com.ibm.mqlight.api.Promise; 24 | import com.ibm.mqlight.api.impl.network.Event.Type; 25 | import com.ibm.mqlight.api.network.NetworkChannel; 26 | 27 | class MockNetworkConnectPromise implements Promise { 28 | 29 | private boolean done = false; 30 | private final LinkedList events; 31 | private NetworkChannel channel = null; 32 | 33 | protected MockNetworkConnectPromise(LinkedList events) { 34 | this.events = events; 35 | } 36 | 37 | @Override 38 | public boolean isComplete() { 39 | synchronized(events) { 40 | return done; 41 | } 42 | } 43 | 44 | @Override 45 | public void setSuccess(NetworkChannel channel) { 46 | synchronized(events) { 47 | events.addLast(new Event(Type.CONNECT_SUCCESS, null)); 48 | done = true; 49 | this.channel = channel; 50 | } 51 | } 52 | 53 | @Override 54 | public void setFailure(Exception exception) { 55 | synchronized(events) { 56 | events.addLast(new Event(Type.CONNECT_FAILURE, exception)); 57 | done = true; 58 | } 59 | } 60 | 61 | protected NetworkChannel getChannel() { 62 | synchronized(events) { 63 | return channel; 64 | } 65 | } 66 | 67 | protected LinkedList getEvents() { 68 | synchronized(events) { 69 | return events; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/network/MockNetworkListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | 23 | import java.util.LinkedList; 24 | 25 | import com.ibm.mqlight.api.impl.network.Event.Type; 26 | import com.ibm.mqlight.api.network.NetworkChannel; 27 | import com.ibm.mqlight.api.network.NetworkListener; 28 | 29 | class MockNetworkListener implements NetworkListener { 30 | 31 | private final LinkedList events; 32 | 33 | protected MockNetworkListener(LinkedList events) { 34 | this.events = events; 35 | } 36 | 37 | @Override 38 | public void onRead(NetworkChannel channel, ByteBuf buffer) { 39 | synchronized(events) { 40 | events.addLast(new Event(Type.CHANNEL_READ, buffer)); 41 | } 42 | } 43 | 44 | @Override 45 | public void onClose(NetworkChannel channel) { 46 | synchronized(events) { 47 | events.addLast(new Event(Type.CHANNEL_CLOSE, null)); 48 | } 49 | } 50 | 51 | @Override 52 | public void onError(NetworkChannel channel, Exception exception) { 53 | synchronized(events) { 54 | events.addLast(new Event(Type.CHANNEL_ERROR, exception)); 55 | } 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /mqlight/src/test/java/com/ibm/mqlight/api/impl/network/MockNetworkWritePromise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.ibm.mqlight.api.impl.network; 20 | 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | import junit.framework.AssertionFailedError; 24 | 25 | import com.ibm.mqlight.api.Promise; 26 | 27 | class MockNetworkWritePromise implements Promise { 28 | private AtomicBoolean done = new AtomicBoolean(false); 29 | 30 | @Override 31 | public boolean isComplete() { 32 | return done.get(); 33 | } 34 | 35 | @Override 36 | public void setSuccess(Boolean drained) { 37 | done.set(true); 38 | } 39 | 40 | @Override 41 | public void setFailure(Exception exception) { 42 | done.set(true); 43 | throw new AssertionFailedError("setFailure should never be called!"); 44 | } 45 | } --------------------------------------------------------------------------------