How to log information in Forge? - java

I'm trying to log into using MinecraftServer.logInfo(), but I get a nosuchmethod exception.
server.logInfo("Example message");
I'm getting the instance of MinecraftServer in the server starting event.
MinecraftServer server = event.getServer();

An option for a fully fledged logger is
Logger logger = LogManager.getLogger(YourMod.MODID);

I'm pretty sure a simple
System.out.println("Information!");
Should do in forge.

Related

Hystrix Dashboard

I'm completly new about Hystrix, however I need to monitor metrics from it.
So far I got a stand alone that display/run the Hystrix Dashboard.
In my project I add the dependencies;
compile(group:"com.netflix.hystrix", name:"hystrix-metrics-event-stream", version:'1.5.5')
compile(group:"org.springframework.cloud", name:"spring-cloud-starter-hystrix-dashboard", version:'1.1.5.RELEASE')
compile(group:"org.springframework.boot", name:"spring-boot-starter-actuator", version:'1.4.0.RELEASE')
compile(group:"org.springframework.cloud", name:"spring-cloud-starter-hystrix", version:'1.1.5.RELEASE')
Also in my SpringConfig I add
#EnableHystrix
public class MyAppConfig {
#Bean
public ServletRegistrationBean servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet(), "/hystrix.stream");
return registration;
}
}
I succesfully boot the services I can check if it is running by localhost:8080/health and get the answer.
When I add localhost:8080/hystrix.stream and hit the button Monitor Streams in the Hystrix Dashboard for a brief time it says "Loading..." but then I get "Unable to connect to Command Metric Stream."
Also I got this in the dashboard console;
17:19:26.858 [vert.x-eventloop-thread-0] INFO c.g.k.h.c.s.d.HystrixDashboardProxyConnectionHandler - Proxing request to http://localhost:8080/hystrix.stream
17:19:31.879 [vert.x-eventloop-thread-0] ERROR c.g.k.h.c.s.d.HystrixDashboardProxyConnectionHandler - Proxying request
java.util.concurrent.TimeoutException: The timeout period of 5000ms has been exceeded
at io.vertx.core.http.impl.HttpClientRequestBase.timeout(HttpClientRequestBase.java:155)
at io.vertx.core.http.impl.HttpClientRequestBase.handleTimeout(HttpClientRequestBase.java:140)
at io.vertx.core.http.impl.HttpClientRequestBase.lambda$setTimeout$0(HttpClientRequestBase.java:100)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:782)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:753)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:316)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Thread.java:745)
17:19:31.894 [vert.x-eventloop-thread-0] ERROR c.g.k.h.c.s.d.HystrixDashboardProxyConnectionHandler - Proxying request
io.vertx.core.VertxException: Connection was closed
at io.vertx.core.http.impl.ClientConnection.handleClosed(ClientConnection.java:396)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:314)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:190)
at io.vertx.core.net.impl.VertxHandler.channelInactive(VertxHandler.java:97)
Finally trying to make a curl localhost:8080/hystrix.stream isn't responding at all.
I'm not sure if missing something anyone could give me a hint please?
Regards.
I think that you are missing #HistrixDashBoard annotation over your main class
If you are using actuator, your stream should be here:
http://localhost:8080/actuator/hystrix.stream

QuickFixJ - quickfix.UnsupportedMessageType: null(Websphere)

I developing something with QuickFixJ and I meet a strange situation. We have a stub to simulate the fix acceptor, locally on my environment is working I can send/receive messages we use a custom message type the quickfixj jar is regenerated based on new dictionary, new message types...
Example message from my env. communication between the FIX initiator and FIX_STUB(acceptor) :
16:49:58.475 [http-8080-4] INFO quickfixj.msg.outgoing - FIXT.1.1:FIX->FIX_STUB: 8=FIXT.1.1|9=267|35=RQS|34=3|49=FIX|52=20160628-13:49:58.474|56=FIX_STUB|20000=1|20001={json string}|20002=1.0|10=171|
<20160628-13:49:58, FIXT.1.1:FIX_STUB->FIX, incoming> (8=FIXT.1.1|9=267|35=RQS|34=3|49=FIX|52=20160628-13:49:58.474|56=FIX_STUB|20000=1|20001={json string}|20002=1.0|10=171|)
16:49:58.476 [QFJ Message Processor] INFO c.r.fix.api.stub.FixApplication - FIX STUB MESSAGE TYPE:quickfix.fix50sp2.Request
<20160628-13:49:58, FIXT.1.1:FIX_STUB->FIX, outgoing> (8=FIXT.1.1|9=308|35=RSP|34=3|49=FIX_STUB|52=20160628-13:49:58.527|56=FIX|20000=1|20001={json string}||20002=1.0|10=240|)
16:49:58.528 [NioProcessor-2] INFO quickfixj.msg.incoming - FIXT.1.1:FIX->FIX_STUB: 8=FIXT.1.1|9=308|35=RSP|34=3|49=FIX_STUB|52=20160628-13:49:58.527|56=FIX|20000=1|20001={json string}||20002=1.0|10=240|
16:49:58.529 [QFJ Message Processor] INFO c....fix.engine.FixEngineImpl - FIX MESSAGE TYPE:quickfix.fix50sp2.Response
on Tomcat is working but when we try to use the exactly same code in a test environment and deploy to a Websphere server I get this error:
2016-06-28 11:17:44,196 appl="rtv" env="SYS" version="3.8.12" loglevel="INFO " message="FIXT.1.1:FIX->FIX_STUB: 8=FIXT.1.19=26735=RQS34=249=FIX52=20160628-09:17:44.19656=FIX_STUB20000=120001={json string}20002=1.010=147" thread="WebContainer : 1" logger="quickfixj.msg.outgoing"
2016-06-28 11:17:44,198 appl="rtv" env="SYS" version="3.8.12" loglevel="INFO " message="FIX STUB MESSAGE TYPE:quickfix.fix50sp2.Message" thread="QFJ Message Processor" logger="c.r.fix.api.stub.FixApplication"
2016-06-28 11:17:44,202 appl="rtv" env="SYS" version="3.8.12" loglevel="ERROR" message="FIX STUB MESSAGE CRACK FAILED" thread="QFJ Message Processor" logger="c.r.fix.api.stub.FixApplication"
quickfix.UnsupportedMessageType: null
at quickfix.fix50sp2.MessageCracker.onMessage(MessageCracker.java:39) ~[quickfixj-messages-all-1.6.2.jar:1.6.2]
at quickfix.fix50sp2.MessageCracker.crack50(MessageCracker.java:1787) ~[quickfixj-messages-all-1.6.2.jar:1.6.2]
at quickfix.fix50sp2.MessageCracker.crack(MessageCracker.java:1555) ~[quickfixj-messages-all-1.6.2.jar:1.6.2]
at com....fix.api.stub.FixApplication.fromApp(FixApplication.java:97) ~[rita-web-3.8.jar:na]
As you can see in the example the type(message sub class) it's handled correctly (quickfix.fix50sp2.Request,quickfix.fix50sp2.Response ) but on Websphere is NOT (quickfix.fix50sp2.Message). MessageCracker is used.
Can you help me to fix this issue, to find out why this is happening is related to OS, web server or some FIX configuration?
I fixed the issue... it was related to classloader and duplicate classes. The way that I got the jar files contained also the default messages(maven dependencies ...) on Tomcat the application pick up the right classes while the WebSphere took the default one this is why the application MessageCracker didn't handled properly the messages.

Log4J SMTPAppender Java

I want to send a mail notification in a java application via log4j. However the first try with configurated log4j.properties file, worked like charm. But since I want a dynamic subject, which is generated in runtime, I tried the following commands, with no success:
final static Logger logger = Logger.getRootLogger();
...
public static mail(String msg, String subj) {
SMTPAppender mailAppend = new SMTPAppender();
mailAppend.setBufferSize(3);
mailAppend.setSMTPHost("smtphostname");
mailAppend.setTo("ex#mple.com");
mailAppend.setSubject(subj);
logger.addAppender(mailAppend);
logger.error(msg);
}
output:
log4j:ERROR Message object not configured.
So did I miss a necessary getter?
An SMTPAppender can be configured either using a xml or properties
file or manually using the setters. When you use the setters, you need
to activate the options by calling the function activateOptions or
else you would get the "ERROR Message object not configured" message.
This is to ensure that the options would only become effective when
all the related options have been set (e.g. one would not want to have
the host setting become effective before the port is set).
FROM : https://community.oracle.com/thread/1758275?start=0&tstart=0

First steps in jclouds

I'm having some problems when I try to connect with my openstack. I'm using jclouds and this is my code:
context = ContextBuilder.newBuilder("openstack-nova")
.endpoint("http://xxx.xxx.xxx.xxx:5000/v2.0/")
.credentials("tenantname:username", "password")
.modules(ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule()))
.buildView(ComputeServiceContext.class);
service = context.getComputeService();
for(ComputeMetadata node: service.listNodes()) {
System.out.println("NODE: " + node.getId());
}
But always it return the following error:
DEBUG [org.jclouds.rest.internal.InvokeHttpMethod] [main] >> invoking AuthenticationApi.authenticateWithTenantNameAndCredentials
DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Sending request -1502473400: POST http://xxx.xxx.xxx.xxx:5000/v2.0/tokens HTTP/1.1
ERROR [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Command not considered safe to retry because request method is POST: [method=org.jclouds.openstack.keystone.v2_0.AuthenticationApi.public abstract org.jclouds.openstack.keystone.v2_0.domain.Access org.jclouds.openstack.keystone.v2_0.AuthenticationApi.authenticateWithTenantNameAndCredentials(java.lang.String,org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials)[tenantname, PasswordCredentials{username=username, password=*****}], request=POST http://xxx.xxx.xxx.xxx:5000/v2.0/tokens HTTP/1.1]
I'm developing in eclipse and Intellij IDEA. I've been reviewing the proxy configuration, but everything is normal.
Please, can anyone help me?
Thanks!
The code looks good, but if you need to go through a proxy you may need to configure the proxy properties in jclouds. Something like the following, with the right values for your proxy:
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_PROXY_HOST, "localhost");
overrides.setProperty(Constants.PROPERTY_PROXY_PORT, "8888");
You can pass the properties to the overrides method of the ContextBuilder.
You can also enable the jclouds.wire logs to see every request and response that are being sent. This will show the exact network error or the one returned by your OpenStack installation. Have a look at: http://jclouds.apache.org/reference/logging/

Starting Elastic Search from java and not form any batch file

I ma totally new to this . . . I want to start Elastic search by java code say by a main method
`Node node = nodeBuilder().local( true ).node();
Client client = node.client();
node.start();`
I used the above code to run it which runs without error but it stops after two seconds only thing that i see in console is
log4j:WARN No appenders could be found for logger (org.elasticsearch.node).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Kindly help guys and here is the link of a similar question but it dint helped
starting elasticsearch instance from java?
If there is nothing else to your code, the issue is that the ES thread on it's own won't keep the program alive. You need to have a thread of your own to keep it alive.. for example:
BasicConfigurator.configure();
Node node = NodeBuilder.nodeBuilder().local(true).node();
node.start();
while (!node.isClosed()) {
try {
Thread.sleep(60*1000);
} catch (InterruptedException e) {
node.close();
}
}
node.stop();

Categories

Resources