Is there any way in Java to receive event notifications whenever link state changes on a computer (connected, disconnected, up, down, etc)? Thanks!
There is no platform-independent mechanism which accomplishes this in Java. However, you can use JNI to do it. For example, Windows allows you to poll (or be notified of) network interface states using the Network Location Awareness (NLA) API.
Related
I'm currently trying to work out what technology I can use to fire events remotely when a database changes, a realtime database of sorts. There is both an android application and a desktop JavaFx app that will communicate via the same database. When the data is changed from the desktop side, I'd like Android to update its data, and vice versa when changes occur on Android. Is there any method to achieve this without polling the DB for changes regularly?
I looked into Firebase and it seemed perfect, but lacked a desktop java library. Similarly, I have experimented with Amazon AWS Lambda and DynamoDB, and I can get a Lambda function to fire when the DynamoDB table changes. I can't however find a way for the Lambda function to update the Android/Desktop application that the data has changed though.
The JavaFx desktop application is a requirement of the project.
Apologies if this isn't possible, or if I'm overlooking a well known platform for this issue. Any help would be greatly appreciated.
No you not need the process of polling to achieve your results. To answer the first question, first the most flexible and plausible approach would to built a middle ware to intercept any changes.
Create a script to fire events whenever the data base changes. Wether by a time interval.
Second create server, a real-time server to fire such events to any client.
Third, the java fx client can use native observable for such a task. However i proposed going with a common listener, a perfect choice would be socket.io, there web-socket implementation available for android and vanilla java. For android client, whenever a data is inserted , transformed etc , use a broadcast receiver(local) to fire events in the to notify the server. Or use the socket.io connection to send events. Thats pretty much it.
Firebase + Cloud Functions for Firebase sound perfect for your use case. If the matter is pure Java support for Firebase, rather than Android, you might want to check out this question Get Firebase to work with java, not Android
I am going to develop uber-like application.Here I have to send latitude and longitude to web and mobile devices continuously with my service,What I have do to get this.
Can anyone please give some idea.
You should start by designing how the application is to be used, seen from all the different users perspectives.
For instance is this a web app, or a native app, or both?
Then from that knowledge, you need to define a communication protocol.
You should be able to determine if the client will be polling for data, or if you need to push it from the server onto the clients.
This also goes for the data that travels the other way.
From here you choose a language for programming, and then start doing some proof of concept tests.
The choice will depend on the chosen underlying technologies
(web / native / os / available libraries)
After some test work you may have something that works, then you need to review or add security to the communication, cause we do not want everyone collecting location data from everyone that has the app installed.
Then run beta trials and eliminate the worst bugs, and then release the app.
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile and web content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
I am implementing a small social networking website, and I am trying to implement notifications.
Notifications have the following requirements
All users will receive notifications whenever users they follow do
certain events (like a post, create a post,leave a comment, etc...
When a set of notifications for a user is unread, just like on facebook, the user will
continue to see a read notification icon on their navbar.
Problem : I am taking an example to describe my problem for better understanding for everyone.
Suppose there are two users A and B. A & B are friends and A post something, suddenly B like the post of A then A should have to receive the notification immediately.
So how can i achieve this immediately receiving of notification process?
Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ? In this case thousand millions of call creating for multiple user. It is feasible solution ?
(I think it create unnecessary load on my website. As i think facebook and stackoverflow do not use this way).
Provide me a suitable solution just like fb and other webiste using.
Technology Using in my project: Java and MYSQL
You should use JavaScript (client side) along with Java - MySql (Server side), and more specifically Ajax. You will need some time to understand the concept and the usage but it does exactly what you want.
To give more details, what you need is to create a partial view where the notifications will appear, and update this partial view async (with AJAX).
Dont reinvent the wheel.
Use ajax call to server at each interval and check your server and update nav acc.
1.So how can i achieve this immediately receiving of notification process?
2) Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ?
Your above both questions answers solve through GWTEventService implementation.
Through it you can write code that will avoid client to server round trip.
GWTEventService is an event-based client-server communication framework. It uses GWT-RPC and the Comet / server-push technique. The client side offers a high-level API with opportunities to register listeners to the server like to a GUI component. Events can be added to a context/domain on the server side and the listeners on the client side get informed about the incoming events. The server side is completely independent of the client implementation and is highly configurable. Domains can be defined to decide which events are important for the different contexts.
Refer link: https://code.google.com/p/gwteventservice/
I'm (sort of) new to android development and I'd like to create an android messenger app based on the PircBot library.
There're several constraints I am aware of right now:
must use IRC, probably can't change this now since it's already in the requirement
IRC service needs to run in its own process so it doesn't interfere with UI while listening to IRC messages and it should receive messages in the background and send notification without having UI showing
I'm using different activities for different screens so all activities will need to use the service (logged in, joined channel, send/recieve message) and different activities should be notified based on the current state of the connection.
I've tried to bind the service from my activity but binder seems to only work with services in the same process. (I'm not sure on this one, search didn't return anything useful)
What's the preferred way to structure my project so that all the constraints can be satisfied? Also what other problems might I ran into?
Sorry for the bad english
IRC service needs to run in its own process so it doesn't interfere with UI while listening to IRC
I don't see any reason why the IRC service would need to run in its own process. A service, is, by definition, an element that does not interact with the user, as stated in the docs:
A Service is an application component representing either an
application's desire to perform a longer-running operation while not
interacting with the user or to supply functionality for other
applications to use.
And, as you said, by making this service run in its own process, it becomes impossible to bind to it (indeed, you need to do IPC communication at that point).
I'm using different activities for different screens so all activities
will need to use the service (logged in, joined channel, send/recieve
message) and different activities should be notified based on the
current state of the connection.
To satisfy this requirement, you can simply use the LocalBroadcastManager to share information from the service to all the activities. Your activities could have BroadcastReceivers for the events they wish to hear (connectionStateChange, MessageReceived, etc.), and would act accordingly.
Finally, because reading other people's code is always a good idea, check out these two similar projects, brought to you by your friendly search engine:
Android's SMS/MMS app
A simple IM app for Android
I'm writing an SWT application which needs to sit in the system tray and pop up automatically whenever the user connects some USB device (the application serves as its control panel).
The way to do this in the native environment (win32 in this case, but I should be platform-independent ultimately) is to listen to the WM_DEVICECHANGE event, then checking if my device has been disconnected.
Googling the subject, it seems like SWT does not in fact handle this type of event. Does anyone have any idea as to how to achieve this? My fallback solution would be sampling the USB port every n seconds, looking for the device, but this is a no-no solution as far as I'm concerned...
Thanks and cheers
Shai
EDIT: J-16 SDiZ reported that the API exists for Windows too
Here is a very good article about Access USB devices from Java applications
The described jUSB module contains a USBListener object.
Interface implemented by objects that want to monitor USB structure. The order in which these changes are reported is not necessarily going to be the order in which the changes were seen in the real world, and delays also occur.
Youre SWt object can implement this listener and do something, when the method
deviceAdded(Device dev)
is fired
Java does not provide direct interaction with the devices and with USB. There are several third-party libraries for Java that provide USB-related features (read/write from USB port). For example: http://www.icaste.com/ (commercial)
Your comment for Zorglub suggests that you have some (presumably) JNI/JNA code to call the 3rd party DLL you mentioned. I assume you could also write a JNI wrapper to the Windows API where you can register to be notified for the _WM_DEVICECHANGE_ event you mentioned.
There is a jUSB port for windows at http://www.steelbrothers.ch/jusb/