Setting the HornetQ Embedded-Remote Example - java

I am having some troubles setting the example in the hornetq-2.3.0.Final jar under the core folder named Embedded-Remote, I am trying to run the example in a "remote enviroment" using for this two computers in the same LAN, if i run the two classes without changing anything in the same computer "EmbeddedRemotExample.java" runs ok, but as this example lacks configuration files I am not sure about how to set this class to connect to a server running in another computer. reading the api I found that this was a valid code:
`
HashMap map = new HashMap();
map.put("host", "192.168.XXX.XXX");
map.put("port", 5445);
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(
new TransportConfiguration(NettyConnectorFactory.class.getName(),map));
ClientSessionFactory sf = serverLocator.createSessionFactory();`
but this produces the next exception
HornetQException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:852)
at org.hornetq.core.example.EmbeddedRemoteExample.main(EmbeddedRemoteExample.java:49)`
How could i set this specific example to work?
in one computer : org.hornetq.core.example.EmbeddedServer
in other one : org.hornetq.core.example.EmbeddedRemoteExample

You need to add the same configuration to the server's Acceptor at EmbeddedServer.java. As by default it would be set to localhost.
I reckon that that example needs a code clean-up:
https://github.com/hornetq/hornetq/pull/1062
This specific commit would make clear what you need to change:
https://github.com/FranciscoBorges/hornetq/commit/fbed7e8394c843e4528df90d4c2ef155a7d032c0

Related

Connecting to an embedded OrientDB server in Java

I'm looking to run a Java process on several machines, each of which will need to start a local OrientBD server, load a graph, perform our processes, then close. As such, I need to be able to embed the OServer start process from within Java.
There is plenty of advice about how to do so, including SA questions, however most seem to be out of date (so please don't mark this as a duplicate prematurely). The most directly relevant seems to be this, however it doesn't work - at least for me. With the below code, I get the subsequent error:
try {
final OServer server = OServerMain.create();
server.startup(server.getClass().getResourceAsStream("/orientdb-server-config.xml"));
server.activate();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
2021-12-07 21:47:39:323 INFO Loading configuration from input stream [OServerConfigurationLoaderXml]
2021-12-07 21:47:39:633 INFO OrientDB Server v3.2.3 (build dc98198215aa57baf29b32adb657dc3733acdb55, branch develop) is starting up... [OServer]java.lang.NullPointerException
at com.orientechnologies.orient.core.Orient.onEmbeddedFactoryInit(Orient.java:957)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.<init>(OrientDBEmbedded.java:97)
at com.orientechnologies.orient.core.db.OrientDBInternal.embedded(OrientDBInternal.java:119)
at com.orientechnologies.orient.server.OServer.startupFromConfiguration(OServer.java:388)
at com.orientechnologies.orient.server.OServer.startup(OServer.java:314)
at ems.definitions.instance.Graph.<init>(Graph.java:47)
I am using OrientDB version 3.2.3; the 'ALL' .jar downloaded from here. Note that this jar does not contain the parameters file orientdb-server-config.xml, so I have downloaded it directly from the source GitHub.
Is there an issue with my specific implementation, my approach in general or with the default config file I'm using? I look forward to hearing your thoughts.
The issue was three-fold:
I was using the 'ALL' .jar provided by the website. Instead I needed to use the libraries provided in the full source.
I did not account for the fact that when the code failed, it did not delete the database it half-created, thus could not execute the code I tried to remedy. I had to implement a temporary fail-safe to drop the database prior to initialisation to avoid this.
I was using the wrong(?) strategy in general.
My working method is as below.
orientDB = new OrientDB("embedded:/tmp/","admin","adminpwd", OrientDBConfig.defaultConfig());
/** THIS IS VERY MUCH ONLY FOR LOCAL TESTING **/
if(orientDB.exists(name))
orientDB.drop(name);
if(!orientDB.exists(name)) // if the database does not already exist, create it.
orientDB.execute("create database " + name + " PLOCAL users ( admin identified by 'adminpwd' role admin)");
db = orientDB.open(name, "admin", "adminpwd");

How to use InMemoryLeaseManager and -CheckpointManager for Azure Event Hub?

I'm trying to connect to an existing Azure Event Hub feed using Java. For my first steps, I'm adjusting the Event Hub Samples project, specifically the EventProcessorSample.
However, it depends on you having an Azure Storage set up which will be used for the ILeaseManager and ICheckpointManager; since I don't have one, I've been looking around and found the InMemoryLeaseManager and InMemoryCheckpointManager classes I'd like to use for my first steps.
However, the protocol for those is that they are first created, then passed to the builder to create a EventProcessorHost, and after that you need to call initialize with the created hostsHostContext`. Here's how I do that:
InMemoryCheckpointManager checkpointManager = new InMemoryCheckpointManager();
InMemoryLeaseManager leaseManager = new InMemoryLeaseManager();
EventProcessorHost processorHost = EventProcessorHost.EventProcessorHostBuilder
.newBuilder(EventProcessorHost.createHostName(hostNamePrefix), consumerGroupName)
.useUserCheckpointAndLeaseManagers(checkpointManager, leaseManager)
.useEventHubConnectionString(eventHubConnectionString.toString(), eventHubName)
.build();
checkpointManager.initialize(processorHost.getHostContext());
leaseManager.initialize(processorHost.getHostContext());
However, EventProcessorHost#getHostContext() is package visible, so the only way to get the above to compile is to put it in a class with package com.microsoft.azure.eventprocessorhost. This will compile but not run, because the original Event Hub package is signed, so running this causes a
Exception in thread "main" java.lang.SecurityException: class "com.microsoft.azure.eventprocessorhost.ILeaseManager"'s signer information does not match signer information of other classes in the same package
So I really have to wonder how you are to supposed to use those utility classes at all.
Of course I can a) implement the interfaces myself or b) create an unsigned Event Hub package, but both don't seem to be what's intended.
Am I missing something?

Create AEM packages via code

Is there a way to create an AEM package via a java code ?
We need to package some content every night via a service run by a cron job.
I checked online and it seems to be possible using a curl command. But either way, I'd need this done via a daily service running a java code.
Please refer to some of the links given below :
1)https://helpx.adobe.com/experience-manager/using/dynamic_aem_packages.html
2)http://cq5experiences.blogspot.in/2014/01/creating-packages-using-java-code-in-cq5.html
The main code goes something like this :
final JcrPackage jcrPackage = getPackageHelper().createPackageFromPathFilterSets(packageResources,
request.getResourceResolver().adaptTo(Session.class),
properties.get(PACKAGE_GROUP_NAME, getDefaultPackageGroupName()),
properties.get(PACKAGE_NAME, getDefaultPackageName()),
properties.get(PACKAGE_VERSION, DEFAULT_PACKAGE_VERSION),
PackageHelper.ConflictResolution.valueOf(properties.get(CONFLICT_RESOLUTION,
PackageHelper.ConflictResolution.IncrementVersion.toString())),
packageDefinitionProperties
);
So first of all you can create a scheduler and in the scheduler's run method you can write the logic to package the required filter paths .
Hoping this is helpful for you.

AS400 JOB Queue via Java jt400

I am just writing an Interface between a java application and an AS400.
For this purpose I use jt400. I managed to get information about the systemstatus like CPU usage, as well I managed to receive the current status about subsystems and jobs.
Now I am searching for an option to have a look at the different job queues inside the AS400.
For example: I would like to know, how many jobs are in which queue.
Is there a solution via jt400 or a different approach to access those information via java?
The corresponding command inside AS400 is WRKJOBQ
Best
LStrike
[Edit]
The following code is my filter for JobList. But how do I configure QSYSObjectPathName that it is matching WRKJOBQ?
QSYSObjectPathName path = new QSYSObjectPathName(.....);
JobList jList = new JobList(as400);
jList.addJobSelectionCriteria(JobList.SELECTION_PRIMARY_JOB_STATUS_JOBQ, true);
jList.addJobSelectionCriteria(JobList.SELECTION_JOB_QUEUE, path.getPath());
Job[] jobs = jList.getJobs(-1, 1);
System.out.println("Jobs Size: " + jobs.length);
You can use a JobList object for that, using SELECTION_JOB_QUEUE to filter jobs.
Once your selection suits your need, JobList#getLength() will give you the number of jobs.
See also this question

How to set system variables from Java?

I need to set certain system variables from within the program. My Google fu is failing me in finding any way to do it. How do I do it? (I am okay with hacky approaches. I need to be able to run this app on Windows, Linux, and Mac.)
Edit:
Adding here my comment from below the post, as it isn't readily visible there:
The best link I could found was this, and it sets the variables only in memory. They do not persist after the program exit.
Edit:
I am writing an installer and need to somehow record at system level that installation happened (along with paths to some directories). The next time user runs the setup, the installer will check if the variables already exist in the system, in which case a user will be given an appropriate warning.
If twiddling with environment variables is not a good idea, what will be the best approach to achieve the above?
Use
following methods of system class
// Get a system property
String dir = System.getProperty("user.dir");
// Set a system property
String previousValue = System.setProperty("application.property", "newValue");
for more details reffer
http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CF8QFjAA&url=http%3A%2F%2Fdocs.oracle.com%2Fjavase%2Ftutorial%2Fessential%2Fenvironment%2Fsysprop.html&ei=oHLgT6agKcborAf_3L3-DA&usg=AFQjCNGWSWRjk3ityPQqreuwx_O7Bp7kdg&sig2=Y1tfYzdXAmNX-hpB8Z64kw
If you want your environment variables to persist after your program ends, I would suggest you use the Properties class. It can be persisted to a file very easily, and vice versa.
First of all, Properties is a java class that is used to hold properties that maybe needed for your program. The basic properties that you are talking about are provided by the operating system. Not all of these can be changed. If you try, you will get a SecutrityException (You can't change the os.name for instance). The basic properties are read from the memory of the computer (basically) you can add additional variables to this by setting environment variables in the operating system you are using. Such as in Win95 you can add to the autoexec.bat the line:
set BARTENDER_NAME=Carl
This line can go in any batch file and BARTENDER_NAME will equal Carl until you reset it.
In your java program If you add the line
System.out.println(System.getProperty("BARTEDER_NAME"));
You'll get Carl as the output.
In the bash shell on Linux or Unix you'd use
BARTENDER_NAME=Carl
export BARTENDER_NAME
You can create your own set of properties for your java program and store them in a file and load them using the Properties load() method.
Hope this helps
from
http://www.coderanch.com/t/387634/java/java/Permanently-setting-System-property
Ok this is off the top of my head so it's extremely hacky and stuff.
Get hold of a process and run the command line command that will set the system variables. This isn't portable but it should suffice for short term till you find a better solution.
Because there is not a standard solution for this, I would recommend you to use a Factory Pattern for this. It means something like:
envManager = null
if system is Windows
`envManager = WindowsEnvManager`
else if system is Linux
`envManager = LinuxEnvManager`
else if system is Mac
`envManager = macEnvManager`
persistEnvironment(envManager);
and the persistEnvironment method would call the specific functions on EnvManager.
How about using Java Preferences API. That way you would store this kind of data in the Registry if you run on Windows. Simple tutorial here.
You can store the preferences per system or per user and the preferences are persistent as well as you desire.
Edit
Example:
package com.stackoverflow.Q11100967;
import java.util.prefs.Preferences;
/**
* #author maba, 2012-06-20
*/
public class App {
public static void main(String[] args) {
Preferences preferences = Preferences.systemNodeForPackage(App.class);
if (!preferences.getBoolean("installed", false)) {
// Install the stuff...
preferences.putBoolean("installed", true);
preferences.put("version", "1.2.3");
}
}
}
On Windows the preferences will be stored at HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Prefs/com/stackoverflow/Q11100967.
In order for this to work you have to run your process with admin privileges or a similar approach.
Edit2
On Linux the preferences would be stored at /etc/.java/.systemPrefs/com/stackoverflow/Q11100967/ in a file called prefs.xml with the following content:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE map SYSTEM "http://java.sun.com/dtd/preferences.dtd">
<map MAP_XML_VERSION="1.0">
<entry key="installed" value="true"/>
<entry key="version" value="1.2.3"/>
</map>

Categories

Resources