comparison JavaSDK/be/uclouvain/orthanc/Peers.java @ 0:3ecef5782f2c

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Oct 2023 17:59:44 +0200
parents
children 26c08ff926a3
comparison
equal deleted inserted replaced
-1:000000000000 0:3ecef5782f2c
1 package be.uclouvain.orthanc;
2
3 /**
4 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8 /**
9 * Java plugin for Orthanc
10 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium
11 *
12 * This program is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see http://www.gnu.org/licenses/.
24 **/
25
26
27 /**
28 * Orthanc peer
29 **/
30 public class Peers {
31 private long self;
32
33 /**
34 * Construct a Java object wrapping a C object that is managed by Orthanc.
35 * @param self Pointer to the C object.
36 **/
37 protected Peers(long self) {
38 if (self == 0) {
39 throw new IllegalArgumentException("Null pointer");
40 } else {
41 this.self = self;
42 }
43 }
44
45 /**
46 * Return the C object that is associated with this Java wrapper.
47 * @return Pointer to the C object.
48 **/
49 protected long getSelf() {
50 return self;
51 }
52
53 @Override
54 protected void finalize() throws Throwable {
55 dispose();
56 super.finalize();
57 }
58
59 /**
60 * Manually deallocate the C object that is associated with this Java wrapper.
61 *
62 * This method can be used to immediately deallocate the C object,
63 * instead of waiting for the garbage collector to dispose the Java wrapper.
64 **/
65 public void dispose() {
66 if (self != 0) {
67 NativeSDK.OrthancPluginFreePeers(self);
68 self = 0;
69 }
70 }
71
72 /**
73 * Return the list of available Orthanc peers.
74 *
75 * This function returns the parameters of the Orthanc peers that are known to the
76 * Orthanc server hosting the plugin.
77 *
78 * @return The newly constructed object.
79 **/
80 public static Peers getPeers() {
81 return new Peers(NativeSDK.OrthancPluginGetPeers());
82 }
83
84
85 /**
86 * Get the number of Orthanc peers.
87 *
88 * This function returns the number of Orthanc peers.
89 *
90 * This function is thread-safe: Several threads sharing the same
91 * OrthancPluginPeers object can simultaneously call this function.
92 *
93 * @return The number of peers.
94 **/
95 public int getPeersCount() {
96 return NativeSDK.OrthancPluginGetPeersCount(self);
97 }
98
99 /**
100 * Get the symbolic name of an Orthanc peer.
101 *
102 * This function returns the symbolic name of the Orthanc peer, which corresponds
103 * to the key of the "OrthancPeers" configuration option of Orthanc.
104 *
105 * This function is thread-safe: Several threads sharing the same
106 * OrthancPluginPeers object can simultaneously call this function.
107 *
108 * @param peerIndex The index of the peer of interest. This value must be lower
109 * than OrthancPluginGetPeersCount().
110 * @return The resulting string.
111 **/
112 public String getPeerName(
113 int peerIndex) {
114 return NativeSDK.OrthancPluginGetPeerName(self, peerIndex);
115 }
116
117 /**
118 * Get the base URL of an Orthanc peer.
119 *
120 * This function returns the base URL to the REST API of some Orthanc peer.
121 *
122 * This function is thread-safe: Several threads sharing the same
123 * OrthancPluginPeers object can simultaneously call this function.
124 *
125 * @param peerIndex The index of the peer of interest. This value must be lower
126 * than OrthancPluginGetPeersCount().
127 * @return The resulting string.
128 **/
129 public String getPeerUrl(
130 int peerIndex) {
131 return NativeSDK.OrthancPluginGetPeerUrl(self, peerIndex);
132 }
133
134 /**
135 * Get some user-defined property of an Orthanc peer.
136 *
137 * This function returns some user-defined property of some Orthanc peer. An
138 * user-defined property is a property that is associated with the peer in the
139 * Orthanc configuration file, but that is not recognized by the Orthanc core.
140 *
141 * This function is thread-safe: Several threads sharing the same
142 * OrthancPluginPeers object can simultaneously call this function.
143 *
144 * @param peerIndex The index of the peer of interest. This value must be lower
145 * than OrthancPluginGetPeersCount().
146 * @param userProperty The user property of interest.
147 * @return The resulting string.
148 **/
149 public String getPeerUserProperty(
150 int peerIndex,
151 String userProperty) {
152 return NativeSDK.OrthancPluginGetPeerUserProperty(self, peerIndex, userProperty);
153 }
154
155 }