Getting info about external processes in linux using JNA- Ptrace? - java

I'm on a student research team currently working on a Java project in which we want to be able to gather some info about specific external programs in CentOS 7. Some potential examples of data we might want to gather would be the URL from firefox, or the coordinates from Google Earth. Thus far, looking into how to implement this has mostly led me to using JNA and ptrace.
Is this a good route to take to tackle this problem? And if so, what can I use to find the location of specific information about the programs in memory?

JNA and ptrace are quite low level things. To run system applications you should use:
exec method of Runtime class
Apache Common Exec
Last one is more useful.
But it seems you don't need to run any application at all. To get information from Google Earth you can just use special web API - Google Maps APIs Web Services. If you want to send HTTP request you should try Apache Http Client. It's very powerful library and i'm pretty sure it's all for you need.
PS. More convenient client Java Client for Google Maps Services
PS1. I think java is the worst choice to work with OS and native applications. I see 2 ways to use it:
write agent on C/C++ which will be gather this information for java manager. It's a hard way
use hacks and tricks like here is there a way to get the url from current tab in google-chrome or here Possible to catch URLs in linux?. It's more easy but you will have restricted amount these hacks. And it will work not for all applications and cases.

Related

Web application, offline mod & synchronisation

We are a group of 6 students in the last year of our studies.
We have to add new features on an existing web application. One of the most important feature and in our opinion the hardest one to implement is the following : the web application has to be functional even when offline.
As for, you must be able to consult data, make changes to the data, and when your device will be able to connect again, the app must try and synchronize with the online database. The current application use the following technologies : apache tomcat / mySQL / Hibernate / JavaEE / JavaScript / Ajax / xHTML & HTML5.
Considering that the main devices that will use the application are mainly digital tablet, smartphones (windows and android, not iOS for now), and windows PC ; my main question is the following one :
How can you do this kind of thing ?
I've done some research and it seems like you have to do a 'second' application, which will use mainly HTML5 to consult data while offline and JavaScript to control what the user is doing and what he can do. But we have no idea about the synchronization. It seems like SQLite could be of use as well
I know this is a general question but we are in the phase where we try and make sure everyone understands what the next steps will be. Thanks for your help and explanations.
Solution-1 : custom solution
There are api available to store data locally called indexDb in javascript which may help to store data.
For synchronisation i found that service workers may help.
Solution-2 : ready made tool
You can also try pouchdb but for this i think at server side you have to take apache couchdb database. I have not used it but would like to try this once.
Take a look at the Service-Worker API. Service worker is a programmable network proxy, allowing you to control how network requests from your page are handled. It's the next generation of giving users an offline experience after the App Cache.
The Service worker - in combination with local storage or even better WebSQL or a polyfill like localforage could be a way to realize that kind of application.
Downside: Service-Worker require SSL, no way around that. Second, only latest chrome and firefox support these technologies.
You might lookup PWA Progressive Web Application as a keyword, which describes / and uses exactly that kind of technologies.

Creating a program to manage Amazon EC2 instances

I am attempting to create a program that can manage EC2 instances (create, stop, terminate). I am unfamiliar with the service, and after looking through documentation and searching the web have not found any general advice on creating a management service. My questions are:
What programming environment/language would best be suited to creating a management program?
How can this program interact with EC2 instances? (I've looked into AWS EC2 command line tools. Can these be used from a program to create/terminate instances?)
Any general advice in accomplishing this is appreciated (links to examples especially).
What programming environment/language would best be suited to creating a management program?
This question cannot be answered in a definite way, rather you should either choose the language you are most comfortable with or that's best suited to your environment/team instead - there are plenty to choose from, most popular major languages are covered by a dedicated SDK (currently Java, .NET, Node.js, Python, PHP, Ruby), see Tools for Amazon Web Services for the detailed listing and links to further information about each.
Please note that there are also two IDE Toolkits listed that might make it easier to get started if you happen to develop in Java or C#, specifically the AWS Toolkit for Eclipse and the AWS Toolkit for Microsoft Visual Studio.
How can this program interact with EC2 instances?
All the SDKs (and also the command line tools build on top of these) do use the AWS APIs to interact with the respective services (each one has a separate API, but most of them are structured very similar), see Documentation for a listing of all currently available services and links to their documentation:
Welcome to the Amazon Web Services (AWS) Documentation. Whether you are new to AWS or an advanced user, you can find useful information about the services ranging from introductions to advanced features.
To learn how you can get started with AWS, see our Getting Started with AWS guide. If you are interested in learning more about our AWS Free Usage Tier, see our AWS free usage tier article.
I guess you are new to the cloud and aws world, you can use AWS Command line tools to management the services. Also to make things pretty simpler you can make use of the readily available aws management console if you are only worry is to start, stop or terminate the instance. Also people have build some thing called Config management system like opscode chef which is built of ruby or you can use puppet built of puppet lab's custom DSL.
I am not sure if you really need a program to do that. The Amazon Management Console ( https://console.aws.amazon.com ) is pretty straight forward, simple to use, you can spin thousands of instances in a very short time. I created 20 instances in about 3 minutes and deleted(terminated) 9 during my first interaction with the technology. Would you provide a use case where this is necessary? Its like you want to create a missile to kill a chicken(rather than buy a knife)
HTH, Thanks,
Bles
I used to work on a project that deals a lot with EC2 and one of my responsibility was to manage instances remotly( deploy/start/stor/reboot). I used Java and the Amazon API to write a communication module for the application.
In addition I made a few general ant scripts to deal with code that has to be deploed into an instance. Kind a old fashion way, but works perfectly :)

JMX "Dashboard" App

I have been playing around with JMX for the last few days and although I don't mind JConsole or the standard JMX web admin tool, it would be nice to create my own web app that somehow queried the registered JMX MBeans and presented a nice, rich-UI-style "dashboard" with charts and graphs; things that the JMX console or JConsole simply do not have.
Is this possible? I've heard of something called a JMX "agent" but not sure if that has anything to do with how JMX can be queried and managed by a dashboard-style app. Thanks in advance!
Jolokia is an agent based approach to JMX which translates JMX native calls to JSON-over-HTTP. It comes with a Javascript library which is perfectly suited for used within the browser. For a sample usage within a web page look at the demo of the Jolokia-Cubism Integration or even better have a look at the blog post from Tomasz Nurkiewicz which gives a very nice example of using Jolokia along with the Highcharts graphing library.
Said all this, there is even more: Ají, Jolokia's fancy sister, has been started as project which will provide an JMX console bundled along with Jolokia clients. I'm still sorting things outs (well, it moves slowly ...), but I think that over the summer more will be there. One can already play around with it and we still look for volunteers (hint ;-) ....
What you are looking to do has probably already been built unless you really want to do it yourself. Have you looked at VisualVM before? I really like it http://visualvm.java.net/mbeans_tab.html/
To write your own application that manages MBeans remotely I think you could start with this tutorial. Seems to be a good starting point.
http://docs.oracle.com/javase/tutorial/jmx/remote/custom.html
One of the comments here is that VisualVM is a profiler. VisualVM isn't a profiler, it's a platform built on top of the NetBeans platform. The platform supports connecting to a VM in flight a number ways including using a JMXConnector to the MBeanPlatformServer, Serviceability Agent (SA), Attach on demand and so on.
VisualVM does contain 2 different profilers but there is also an MBean plugin that allows you to view and manipulate MBeans that have been registered with the MBeansPlatformServer.
A number of the view in VisualVM scrape data from the MXBeans found in the java.lang.management package that are registered with the MBeansPlatformServer. Many of these MXBeans are wrappers over the SA, a component of HotSpot that maintains a set of performance counters. For example, counters can give you some information about JIT compiler activity, GC activity and even host platform CPU utilization and so on.
You can easily build your own plugins to view or manipulate MBeans. The tutorial mentioned in a posting here is one source of information as to how to get it done. I have written a demonstration VisualVM plugin that looks at data from the MemoryPool MXBeans. That plugin has been augmented by others to do a number of other things. All the code can be found at java.net in the project MemoryPoolView. It covers reading data. However executing functionality is really just executing a method against the JMXConnector with the parameters required by the MBean you are interacting with. IOWs, it's a fairly trivial extension of the plugin.
HawtIO Is about the best plug-and-play, works out of the box solution for getting JMX stuff on a web page. You can put multiple mbeans on the same page and see them all at once, it works in a browser, you don't have to write a bunch of front-end code yourself, and it can be done without opening up weird ports that your IT department will get nervous about. The data visualization options that work with the simple drag and drop interface are pretty minimal, but there is documentation for writing more advanced plugins.
The backend uses Jolokia to put an HTTP REST interface on JMX, which is probably going to be true for any solution you might look at.

PHP to Java migration

We are occasionally in a position to take over PHP based projects, but as we are a Java-house we are searching for ways to turn a PHP-project (or codebase) into a Java-project.
The approaches we came up to work in a mixed Java/PHP context are :
PHP in frontend and Java in backend with separate front (PHP+JavaScript) and back (Java+SQL) teams
using both technologies in a Java webapp, for example via Quercus with one or multiple teams
migrating everything to Java
We haven't tried any of these approaches as we've been lucky enough to have enough Java-only projects to work on.
Do you see other approaches, or have you tried any of the described approaches?
I've used Quercus. I think that if it supports something like Drupal then it's probably fairly mature. If your PHP app works out of the box, then it offers you a very gradual upgrade path to Java since you can write your own plugins in Java and expose them to the PHP layer, such as using a JDBC back-end.
How easy it is all depends on how well separated the layers are in the PHP application. For example, if the view layer is well separated, you might be able to replace both controller and model logic with a Spring MVC application that uses a 'QuercusView' for the view - you may be able to re-use a lot of the PHP view logic.
You should also consider how you can make a survey of the PHP code - maybe a script that extracts all the function calls, imports etc. so you can quickly test the Quercus support for them.
Sorry, I haven't used the PHP-Java bridge, but I think the Quercus library is pretty mature these days, so that would be my first choice for a staged migration.
My experiences with Querces are not so good. Maybe it has improved, but when I tried it something like two years ago (a long time, I know) it was far from complete and did not support all functions yet. Also, if your application is using some extensions (e.g. from PECL) you will experience difficulties getting this up and running under Querces.
We're currently in the process of migrating a web application from PHP to Java. We're designing a SOA and we'll probably replace some data access objects in the PHP application with a version that talks to internal webservices. Currently we're using Thrift as protocol for our internal webservices, a framework that also has a client available for PHP. We expect this to increase flexibility during migration (allowing us to do step-by-step migration, rather than all-at-once)
PHP/Java Bridge may be of your interest:
The PHP/Java Bridge is an
implementation of a streaming,
XML-based network protocol, which can
be used to connect a native script
engine, for example PHP, Scheme or
Python, with a Java virtual machine.
It is up to 50 times faster than local
RPC via SOAP, requires less resources
on the web-server side. It is faster
and more reliable than direct
communication via the Java Native
Interface, and it requires no
additional components to invoke Java
procedures from PHP or PHP procedures
from Java.
NUMITON may be useful for you:
http://java.dzone.com/announcements/automated-translations-php-jav
The shortest route from PHP to Java
Numiton offers an automated alternative to migrating PHP codebase. This way,
established applications can benefit from the advantages offered by Java in its
enterprise-level capacity.
Some of the risks inherent to any software migration are avoided by using an automated
translation tool. Our PHPtoJava product performs variable type inference,
objectualization and other operations in a uniform manner, the resulting appearance and
behavior being identical to what the users already know.
Of course, the human factor still plays an important role in the post-translation
phases: application fine-tuning and functional testing. The speed and accuracy of the
entire process surpass however those of a manual translation.
One of the applications we have migrated this way is the well-known forum engine
phpBB. The translation result, nBB2, powers our own forum and was recently donated to the
open-source community as a SourceForge project.
PHP in frontend and Java in backend
with separate front (PHP+JavaScript)
and back (Java+SQL) teams
This is technically feasible using SOAP.
using both technologies in a Java
webapp, for example via Quercus with
one or multiple teams
I have no idea about this
migrating everything to Java
This is better option, but it will take time depending on the size & complexity of your project.
I do not have any experience running PHP inside a JVM, but I am betting that IBM does. :)
You might consider Project Zero.
http://www.projectzero.org/php/
Seems similar to Querces or that other thing someone linked. The only other thing that you didn't mention that I can think of is to refactor the PHP code because I'm assuming that its an older codebase written in a PHP 4 manner.
I know this is 2 years old question but i still want to contribute. We are migrating from full java portal to php+java. We have 14 million users. This design doesn't need web services because we use java as json provider for php and js. We will see the result soon...
PHP in frontend and Java in backend with separate front
(PHP+JavaScript) and back (Java+SQL) teams

Please suggest some solutions for building a download service

I'm planning a web service providing file download service for handheld devices.
The requirement I have is use HTTP or FTP Protocol to build a server, use database, store files and provide Command Line Interface for devices to download requested files. No platforms and languages limit.
I'm a student and I'm learning Java Web(practicing Structs2, haven't started learnning Spring or Hibernate), and this is just a simulate project which may be required in a E-Book company. So I'm feeling like to use Java to build the service.
I'm now doing the requirement analysis, please give me some suggestions. About how to design the structure, book files stored in database or filesystem, any open source library to refer to... About any aspect is OK.
I just want to know what can I do to make it better and where I should be paying attention to.
You could implement a simple Servlet, which returns files based on request arguments.
Then, use your command line client to call the Servlet with the correct parameters, depending on what the user typed.
EDIT: more info on Java Servlet technology here. If you are learning Struts, you could implement your servlet there, but it might be a bit of overkill.

Categories

Resources