View Javadoc

1   /*
2    * Copyright (C) 2012 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.atlassian.jira.rest.client.internal.async;
17  
18  import com.atlassian.jira.rest.client.api.*;
19  
20  import javax.ws.rs.core.UriBuilder;
21  import java.io.IOException;
22  import java.net.URI;
23  
24  /**
25   * Asynchronous implementation of JIRA REST com.atlassian.jira.rest.client.
26   *
27   * @since v2.0
28   */
29  public class AsynchronousJiraRestClient implements JiraRestClient {
30  
31  	private final IssueRestClient issueRestClient;
32  	private final SessionRestClient sessionRestClient;
33  	private final UserRestClient userRestClient;
34  	private final ProjectRestClient projectRestClient;
35  	private final ComponentRestClient componentRestClient;
36  	private final MetadataRestClient metadataRestClient;
37  	private final SearchRestClient searchRestClient;
38  	private final VersionRestClient versionRestClient;
39  	private final ProjectRolesRestClient projectRolesRestClient;
40  	private final DisposableHttpClient httpClient;
41  
42  	public AsynchronousJiraRestClient(final URI serverUri, final DisposableHttpClient httpClient) {
43  		final URI baseUri = UriBuilder.fromUri(serverUri).path("/rest/api/latest").build();
44  
45  		this.httpClient = httpClient;
46  		metadataRestClient = new AsynchronousMetadataRestClient(baseUri, httpClient);
47  		sessionRestClient = new AsynchronousSessionRestClient(serverUri, httpClient);
48  		issueRestClient = new AsynchronousIssueRestClient(baseUri, httpClient, sessionRestClient, metadataRestClient);
49  		userRestClient = new AsynchronousUserRestClient(baseUri, httpClient);
50  		projectRestClient = new AsynchronousProjectRestClient(baseUri, httpClient);
51  		componentRestClient = new AsynchronousComponentRestClient(baseUri, httpClient);
52  		searchRestClient = new AsynchronousSearchRestClient(baseUri, httpClient);
53  		versionRestClient = new AsynchronousVersionRestClient(baseUri, httpClient);
54  		projectRolesRestClient = new AsynchronousProjectRolesRestClient(serverUri, httpClient);
55  	}
56  
57  	@Override
58  	public IssueRestClient getIssueClient() {
59  		return issueRestClient;
60  	}
61  
62  	@Override
63  	public SessionRestClient getSessionClient() {
64  		return sessionRestClient;
65  	}
66  
67  	@Override
68  	public UserRestClient getUserClient() {
69  		return userRestClient;
70  	}
71  
72  	@Override
73  	public ProjectRestClient getProjectClient() {
74  		return projectRestClient;
75  	}
76  
77  	@Override
78  	public ComponentRestClient getComponentClient() {
79  		return componentRestClient;
80  	}
81  
82  	@Override
83  	public MetadataRestClient getMetadataClient() {
84  		return metadataRestClient;
85  	}
86  
87  	@Override
88  	public SearchRestClient getSearchClient() {
89  		return searchRestClient;
90  	}
91  
92  	@Override
93  	public VersionRestClient getVersionRestClient() {
94  		return versionRestClient;
95  	}
96  
97  	@Override
98  	public ProjectRolesRestClient getProjectRolesRestClient() {
99  		return projectRolesRestClient;
100 	}
101 
102 	@Override
103 	public void close() throws IOException {
104 		try {
105 			httpClient.destroy();
106 		} catch (Exception e) {
107 			throw (e instanceof IOException) ? ((IOException) e) : new IOException(e);
108 		}
109 	}
110 }
111