View Source

h2. Connect to {{KIMService}}, deployed on a specific host and port


To connect to {{KIMService}}, you need to specify the RMI host name (IP) and RMI port, and call:
{code:java}
// ----------------------------------------------------------------------------------
// connect to KIMService (deployed on specific host and port)
// ----------------------------------------------------------------------------------
// this will try connect to KIM service on RMI_HOST and RMI_PORT specified within
// "./kim_connection.properties" file located in your application running directory
// if no such file or no such properties are defined the defaults are "localhost:1099"
KIMService serviceKim = GetService.from();

// you may also use the following if you want to connect specific RMI_HOST
// KIMService serviceKim = GetService.from(RMI_HOST);

// you may also use the following if you want to connect specific RMI_HOST and RMI_PORT
// KIMService serviceKim = GetService.from(RMI_HOST, RMI_PORT);

System.out.println("KIM Server connected.");
// ----------------------------------------------------------------------------------
{code}

(!) If your application working directory doesn't contain a config file {{kim_connection.properties}}, the default localhost and port:1099 will be used for the method {{{_}GetService.from()_}}. Alternatively, in order to connect to {{KIMService}} on a specific host and port, you must use the methods that take host and port as parameters.
If your application folder contains such a file, you must set the following variables in it:
{code:java}
RMI_HOST = <put host name or IP here>
RMI_PORT = <put port number here>
{code}

After {{KIMService}} is connected, you can use the {{{_}getVersion()_}} method to check the KIM version.
{code:java}
// ----------------------------------------------------------------------------------
// check/display KIM version
// ----------------------------------------------------------------------------------
System.out.println("KIM Platform : " + serviceKim.getVersion());
// ----------------------------------------------------------------------------------
{code}


h2. Obtain a Component (e.g. {{DocumentRepositoryAPI}}, {{SemanticRepositoryAPI}}, etc.)


Each component gives access to a corresponding API interface. Obtaining a component when connected to {{KIMService}} is done by calling the appropriate {{{_}get()_}} method as shown below.
{code:java}// ----------------------------------------------------------------------------------
// obtain component (e.g. DocumentRepositoryAPI, SemanticRepositoryAPI, etc.)
// ----------------------------------------------------------------------------------
CorporaAPI apiCorpora = serviceKim.getCorporaAPI();
System.out.println("CorporaAPI obtained successfully.");

DocumentRepositoryAPI apiDR = serviceKim.getDocumentRepositoryAPI();
System.out.println("DocumentRepositoryAPI obtained successfully.");

SemanticAnnotationAPI apiSemAnn = serviceKim.getSemanticAnnotationAPI();
System.out.println("SemanticAnnotationAPI obtained successfully.");

QueryAPI apiQuery = serviceKim.getQueryAPI();
System.out.println("QueryAPI obtained successfully.");

SemanticRepositoryAPI apiSemanticRepository = serviceKim.getSemanticRepositoryAPI();
System.out.println("SemanticRepositoryAPI obtained successfully.");

CoreAPI apiCoreDb = serviceKim.getCoreDbAPI();
System.out.println("CoreDbAPI obtained successfully.");
// ----------------------------------------------------------------------------------
{code}
A successful {{KIMService}} connection is essential for implementing all examples and looks like this:
{code:java}// ----------------------------------------------------------------------------------
// connect to KIMService (deployed on specific host and port)
KIMService serviceKim = GetService.from();
System.out.println("KIM Server connected.");

// obtain CorporaAPI and DocumentRepositoryAPI components
CorporaAPI apiCorpora = serviceKim.getCorporaAPI();

DocumentRepositoryAPI apiDR = serviceKim.getDocumentRepositoryAPI();

System.out.println("CorporaAPI and DocumentRepositoryAPI obtained successfully.");
// ----------------------------------------------------------------------------------
{code}