Can you build stand-alone Apache Pivot application, i.e. not run in browser? - apache-pivot

Can you build stand-alone Apache Pivot application, i.e. not run in browser?

yes, you can.
public static void main(String[] args) {
DesktopApplicationContext.main(UI.class, args);
}

Related

Run JAX-WS on JavaME

I have simple web service application created on JAX-WS. I need to move this application on embedded device that runs Java micro edition. Is it possible run JAX-WS on Java micro edition?
public class Srv
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
javax.xml.ws.Endpoint.publish("http://0.0.0.0:8080/RFIDMngr", new Mngr());
}
}
What is the best way to move web service application to JavaME?

Use "using" statement around BuildWebHost?

In ASP.NET Core 2.x, the best practice is to have a method called BuildWebHost that is called in the app's main entry point (see the MSDN article Hosting in ASP.NET Core):
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
IWebHost is IDisposable, so in the spirit of being a good .NET citizen, would it be advisable to surround BuildWebHost with a using statement?
public class Program
{
public static void Main(string[] args)
{
using (var host = BuildWebHost(args))
{
host.Run();
}
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
No. Use it as is. IWebHost implements IDisposable because it is and can be used in other ways, where you may need to manually dispose of it. However, in the context here, it's the whole kit and kaboodle. It is created when the program starts and continues to be used until the program ends.
As a slightly better explanation, understand that the only reason to dispose of resources is to remove them from memory while the application is continuing to run. Eventually the GC will get rid of abandoned resources whether you dispose or not, but you should never rely on the GC to clean up after you. If you no longer need a resource, you dispose of it, in order to reduce the continued resource load of your application, again, while it's continuing to run.
When your application ends, all associated resources go away with it, as it's all tied to the process. If there's no process, there's nothing left in RAM. Hence why it's unnecessary to manually dispose of IWebHost in this context. Since it will be need until the application ends, and when the application ends, it will be completely gone, no matter what, disposing manually buys you nothing.

How to add EventSource to a web application

We finally got EventSource and ElasticSearch correctly configured in our service fabric cluster. Now that we have that we want to add EventSources to our web applications that interact with our service fabric applications so that we can view all events (application logs) in one location and filter / query via Kibana.
Our issue seems to be related to the differences between a service fabric app which is an exe and a .NET 4.6 (not .net CORE) web app which is stateless. In service Fabric we place the using statement that instantiates the pipeline in Program.cs and set an infinite sleep.
private static void Main()
{
try
{
using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("CacheApp-CacheAPI-DiagnosticsPipeline"))
{
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Endpoint).Name);
// Prevents this host process from terminating so services keeps running.
Thread.Sleep(Timeout.Infinite);
}
How do I do this in a web app? This is the pipeline code we are using for a non ServiceFabric implementation of the EventSource. This is what we are using:
using (var pipeline = DiagnosticPipelineFactory.CreatePipeline("eventFlowConfig.json"))
{
IEnumerable ie = System.Diagnostics.Tracing.EventSource.GetSources();
ServiceEventSource.Current.Message("initialize eventsource");
}
We are able to see the pipeline and send events to ElasticSearch from within the using statement but not outside of it. So the question is:
how/where do we place our pipeline using statement for a web app?
Do we need to instantiate and destroy the pipeline that every time we log or is there a way to reuse that pipeline across the stateless web events? It would seem like that would be very expensive and hurt performance. Maybe we can we cache a pipeline?
That’s the jist, let me know if you need clarification. I see lots of doco out there for client apps but not much for web apps.
Thanks,
Greg
UPDATE WITH SOLUTION CODE
DiagnosticPipeline pipeline;
protected void Application_Start(Object sender, EventArgs e)
{
try
{
pipeline = DiagnosticPipelineFactory.CreatePipeline("eventFlowConfig.json");
IEnumerable ie = System.Diagnostics.Tracing.EventSource.GetSources();
AppEventSource.Current.Message("initialize eventsource");
}
}
protected void Application_End(Object sender, EventArgs e)
{
pipeline.Dispose();
}
Assuming ASP.NET Core the simplest way to initialize EventFlow pipeline would be in the Program.cs Main() method, for example:
public static void Main(string[] args)
{
using (var pipeline = DiagnosticPipelineFactory.CreatePipeline("eventFlowConfig.json"))
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
}
This takes advantage of the fact that host.Run() will block until the server is shut down, and so the pipeline will exist during the time when requests are received and served.
Depending on the web framework you use things might vary. E.g. if the one you use offers "setup" and "cleanup" hooks, you could create a diagnostic pipeline during setup phase (and store a reference to it in some member variable), then dispose of it during cleanup phase. For example, in ASP.NET classic you'd put the code in global.asax.cs and leverage Application_OnStart and Application_OnEnd methods. See Application Instances, Application Events, and Application State in ASP.NET for details.
Creating a pipeline instance every time a request is served is quite inefficient, like you said. There is really no good reason to do that.

IIS module: Init() is called only once in a website?

I need to add an IIS module for some processing. Here is my module:
namespace MyNamespace
{
public class MyModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
//I hope to do some work here ONLY once for all requests
context.ReleaseRequestState += new EventHandler(myHandler);
}
#endregion
public void myHandler(Object source, EventArgs e)
{
//do some work...
}
}
}
I need to do some resources-consuming work in the Init() method. I HOPE that Init is called ONLY once in a website and is called again only when the website is restarted in IIS Manager.
Can an expert in this tell me whether Init() works as I hope for?
Thanks!
For ANY requests being carried out, it will always call this method so no, it is not for the first time the app pool spins up. What you may wish to do is have a static variable in there to see if it truly is the first time its been hit and if not, carry on with what you need otherwise ignore it. ensure you lock around the portion of code when you are setting the variable to true.
Remember, IIS has application pools which websites use (generally speaking). There will be multiple concurrent requests coming into IIS to process and what happens? The app pool executes to serve the request to the website therefore multiple "hits" will be executed for the Init() for the HttpModule but once per application, if that makes sense.
Every one of them initializes their own list of modules.
you DO have the option of using the Application_Start event in the global asax which will only ever execute once per application (when the app pool spins up and the request is being submitted) - perhaps you can use this for your needs, which would be a better option.

Business objects XI 3.1 how to deploy and run the java jar file on to the server

I'm newbie to SAP Business objects XI 3.1. I would like to run the sample java class on the BO XI 3.1 server. when I login to XI 3.1 console, couldn't find a way to deploy the java class and run it on the server. My class is really simple.
public class BOJavaTest {
public static void main(String[] args) {
System.out.println("Entering the Main class");
System.out.println("Exiting the Main class");
}
any help would be appreciated
You have to make a jar and then publish it as a new object on the Central Management Console
choose the folder that you want to deploy your jar in
select the tab Object
click on New Object
The rest should be easy for you.
Things to don't forget :
in the process tab of your program, don't forget to put your main class to run.

Resources