Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call SPL script remotely by Java

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

In "how Java invokes SPL scripts", we introduced that aggregator JDBC can be deployed in Java to call local SPL scripts, so how can SPL scripts be called remotely in Java? That's what I'm going to say!

The idea of implementation is clear at a glance through the following figure:

Deploy the server

The server is an analytical-oriented high-performance database running on the Java platform. As a high-performance computing data warehouse, the server can provide efficient computing output in offline batch running, online query, multidimensional analysis and in-memory computing to help users solve a variety of problems in computing.

Let's first learn about the use and configuration of the server. for more information about the server, please refer to the "tutorials" server section of the online documentation of the aggregator.

1. Server configuration

In the esProc\ bin path of the aggregator installation directory, you can find the esprocs.exe file, which you can run directly to start or configure the server. When using esprocs, the required jar packages are automatically loaded under the installation path, but it is important to note that the configuration files raqsoftConfig.xml and unitServer.xml used at this time must be placed under the esProc\ config path of the aggregator installation directory. After running, the window opens as follows:

When esprocs.exe executes, the window displays information about the initial settings for loading, which are actually determined by the configuration file raqsoftConfig.xml. Click Options in the menu bar on the right to configure information about the server. The server configuration window pops up as follows:

On the page, you can configure information such as license file, primary path, addressing path, date-time format, default character encoding, log level, number of bytes in file cache, and so on.

Let's continue to learn about the server configuration. Click Config in the menu bar on the right to configure the extension information. Click on the Unit page to configure the extension information, as shown below:

Temp file timeout sets the life cycle hours of temporary files; Check interval must be set to a positive value or 0 to check the number of seconds between expiration; and Proxy timeout is the agent life cycle, that is, the number of life hours of remote cursors and task space. If Temp file timeout or Proxy timeout is set to 0, expiration is not checked.

In the extension list Host list, you can configure all the extensions on the local machine that may be used to run the server, and configure their IP addresses. In the process list Process list, you can configure the port Port of multiple processes for an IP address, of which the first is the primary process. When the server starts, it automatically looks for an extension with an idle process in the extension list, and then the extension hands the task to a process to execute. It should be noted that the IP address needs to be the real IP of the machine, and multiple IP can be set when using multiple network cards.

In the extension configuration, Max task number is the maximum number of jobs allowed for this extension, while Preferred task number is the appropriate number of jobs for this extension. When multiple processes are used in the extension, the number of suitable jobs is the total number of sub-processes. In the Partitions column, you can select the partition used on each extension.

The client whitelist can be set in the Enable clients page of the server, as follows:

When Check clients is selected, you can set the whitelist of IP addresses allowed to call the server in the Clients hosts list. IP addresses that are not in the set range will not be able to call the server to perform calculation.

After the server is set, click OK, and the corresponding configuration file unitServer.xml can be automatically set as follows:

12180012121800122. Run the server

After the server is configured, click Start in the extension operation window to start running the server. If you need to stop the service, you can click Stop. When the server stops, you can click Quit to exit. If you click Reset, the service will initialize and restart, clearing all global variables and memory areas.

When the extension starts, each set process will start at the same time. You can click Main to view the execution of the extension main process, or click the corresponding port number to view the execution page of other extension processes.

On Linux systems, you can run ServerConsole.sh to start the server class:

The extension running window that opens is the same as under Windows:

In addition, you can add the-p parameter when you execute the command, non-graphically start the server, and the server will execute directly:

Deploy aggregator JDBC

Put the jar package and configuration file needed to load the aggregator when you start the JAVA application into the project. It is important to note that the JDK version required by the aggregator JDBC must not be less than 1.6.

1. Load driver jar

The aggregator JDBC is similar to a database JDBC driver without physical tables, which can be simply regarded as a database with only stored procedures. In addition, the aggregator JDBC is a completely embedded computing engine, which has completed all the operations in JDBC. Unlike the database, JDBC is just an interface, and the actual operation is done in an independent database server.

If you are in the web application project, you can put these jar packages in the WEB-INF/lib directory. The aggregator JDBC requires three basic jar packages, all of which can be found in the [installation directory]\ esProc\ lib directory:

Dm.jar / / aggregator computing engine and JDBC driver package icu4j_3_4_5.jar / / handles internationalization jdom.jar / / parsing configuration files dm.jar / / aggregator computing engine and JDBC driver package icu4j_3_4_5.jar / / handles internationalization jdom.jar / / parsing configuration files

In addition to the required jar above, there are some jar packages for specific functions:

For example, if the database is used as a data source, then the driver jar package of the corresponding database is also required.

To read and write Office files, you need to join poi*.jar and xmlbeans.jar;. To use the drawing function, you need to add jar packages related to SVG graphics processing, including batik*.jar, js.jar, pdf-transcoder.jar, xalan-2.6.0.jar, xercesImpl.jar, xml-apis.jar, xml-apis-ext.jar.

two。 Deploy raqsoftConfig.xml

The aggregator also has an important configuration file raqsoftConfig.xml, which can be found in the [installation directory]\ esProc\ config. It needs to be copied and placed under the classpath of the application project. The name of the configuration file cannot be changed.

In the raqsoftConfig.xml file, various kinds of information are configured, such as authorization information, main path of aggregator, dfx file addressing path, server address of JDBC remote access, and so on. Let's first look at the most basic configuration, that is, the configuration of the aggregator authorization file and the server address:

Esproc.xml 192.168.107.1 esproc.xml 192.168.107.1 Java call

Next, let's take accessing the data file on the server as an example to show how to access the server remotely in Java.

Through SPL, Java can not only access local files, but also remotely access data files on the server, including Txt, Excel, Json, Csv, Ctx and other files.

When accessing, you can check the file location through the absolute path, or you can find it through the relative path. The absolute path and relative path here will be found on the server. When using a relative path, it is relative to the home directory in the raqsoftConfig.xml configuration file on the server, so first let's configure the home directory on the server:

Add the following nodes to the nodes in the raqsoftConfig.xml file:

D:\\ mainFile D:\\ mainFile

We put the file employee.txt to be called under the home directory of the server. The Java code is as follows:

Public void runSPL () throws ClassNotFoundException, SQLException {Connection con = null; PreparedStatement st; ResultSet set; / / establish a connection Class.forName ("com.esproc.jdbc.InternalDriver"); / / onlyServer is used to control whether the current jdbc performs remote computing on the server, indicating remote computing for true False indicates local calculation / / Note: the attribute value is false. When the SPL statement uses call dfx or dfx, the local calculation will be used first. If the calculation is not successful, the remote calculation con= DriverManager.getConnection ("jdbc:esproc:local://?onlyServer=true") will be performed. / / execute the SPL statement directly and return the result set st = (PreparedStatement) con.createStatement (); ResultSet rs = st.executeQuery ("$select * from employee.txt") / / simply process the result set and output the field names in the result set with the data output ResultSetMetaData rsmd = rs.getMetaData (); int colCount = rsmd.getColumnCount (); for (int c = 1; C1) {System.out.print ("\ t");} else {System.out.print ("\ n");} System.out.print (title) } while (rs.next ()) {for (int c = 1; C1) {System.out.print ("\ t");} else {System.out.print ("\ n");} Object o = rs.getObject (c); System.out.print (o.toString ()) }} / / close connection if {con.close ();}} public void runSPL () throws ClassNotFoundException, SQLException {Connection con = null; PreparedStatement st; ResultSet set; / / establish connection Class.forName ("com.esproc.jdbc.InternalDriver"); / / onlyServer is used to control whether the current jdbc performs remote computing on the server, indicating remote computing for true False indicates local calculation / / Note: the attribute value is false. When the SPL statement uses call dfx or dfx, the local calculation will be used first. If the calculation is not successful, the remote calculation con= DriverManager.getConnection ("jdbc:esproc:local://?onlyServer=true") will be performed. / / execute the SPL statement directly and return the result set st = (PreparedStatement) con.createStatement (); ResultSet rs = st.executeQuery ("$select * from employee.txt") / / simply process the result set and output the field names in the result set with the data output ResultSetMetaData rsmd = rs.getMetaData (); int colCount = rsmd.getColumnCount (); for (int c = 1; C1) {System.out.print ("\ t");} else {System.out.print ("\ n");} System.out.print (title) } while (rs.next ()) {for (int c = 1; C1) {System.out.print ("\ t");} else {System.out.print ("\ n");} Object o = rs.getObject (c); System.out.print (o.toString ()) }} / / close the connection if (contextual null) {con.close ();}}

Execution result:

Summary

Through the use of the above, I believe you already know the deployment core of the remote access server, yes! The procedure for invoking the operation on the server in the Java program is basically the same as calling the local SPL operation. To sum up, there are three main differences:

1, deploy the server

2add server address to the raqsoftConfig.xml of JDBC

3. Add the onlyServer attribute to the url of JDBC. The attribute value is true, and the server is always accessed for remote calculation. The attribute value is false, which is calculated locally, but when the SPL statement is call dfx or dfx, it will be calculated locally first. If the calculation is not successful, remote calculation will be carried out.

At this point, this is the end of the introduction to remote calling SPL scripts. For more information on the use of SPL when calling in Java, please see "how Java calls SPL scripts". Of course, friends who want to learn more about SPL can also check it in the online tutorials on the official website.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report