Java code to handle node failure in jgroups cluster - java

My Jgroups config file contains the protocol/config
<FD timeout="3000" max_tries="3" />
But how do I use this in the Java code. For example, if there is a cluster and when I detect a failure I want to call an external notifier service via a REST call, like /nodeDown/nodeID
I'm not able to find any java code which does this, all I see is message receive and send, is there a way I can implement this?
Thanks
Adding some more info
I have done the step of writing a RecieverAdpater and override the start, stop, send, recieve method. Please find some code here,
public void receive(Message msg) {
JGroupsDataPacket pckt = (JGroupsDataPacket) msg.getObject();
if ( pckt.getCmd().equals("cacheUpdate") ){
int uid = pckt.getAffectedUid();
cacheUpdateRoutine(uid);
}
if ( pckt.getCmd().equals("ack") ){
System.out.println("got the mesaage!");
}
logger.log(LogLevel.ERROR, "received msg from " + msg.getSrc() + ": " + msg.getObject());
}
public void send(JGroupsDataPacket pckt){
Message msg = new Message(null, null, pckt);
msg.setFlag(Message.Flag.RSVP);
try {
channel.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
I want to know where should I add code for example to handle the TimeOutException when I'm sending a message with the RSVP flag enabled. Another requirement is to know, which is the Java callback method which is called when SUSPECT(P) is triggered. I want to catch and handle the machine's going down, timout etc.
Is the viewAccepted() the only place where I can handle this? Is there a sample code around this?
Also is http://www.jgroups.org/manual/html/user-channel.html
the section 3. APIs give all java/programmatic things we can do with JGroups.
Thanks again
I found some documentation here, I think this is the class which I'm supposed to override
public interface MembershipListener {
void viewAccepted(View new_view);
void suspect(Object suspected_mbr);
void block();
void unblock();
}

OK, first off, you have a JChannel. You need to use it to register for view callbacks, like this:
JChannel ch;
ch.setReceiver(this);
'this' extends ReceiverAdapter and overrides viewAccepted():
public void viewAccepted(View view) {
// handle new view
}
To determine the members which left between views v1 and v2:
List<Address> left_mbrs=View.leftMembers(v1,v2);

Related

Java/Com4J/IMAPI2. Unable to subscribe to WriteEngine events (BurnDVD application)

I'm developing an application with burning DVD functionality. The IMAPI2 interfaces stack is provided by a COM object, and I've managed to hook into it using com4j. Now the application is able to burn DVD successefully but unfortunately, I'm not able to capture writing-events during burn. I wonder if somebody can take a look on the code and advise how to subsribe to write engine events correctly. When I'm trying to use this code:
IDiscRecorder2 recorder = ClassFactory.createMsftDiscRecorder2();
String recorderUniqueId = dm.item(0);
// initialize disk recorder
recorder.initializeDiscRecorder(recorderUniqueId);
// Define the new disc format and set the recorder
IDiscFormat2Data dataWriter = ClassFactory.createMsftDiscFormat2Data();
dataWriter.recorder(recorder);
// TODO Need subscribe to writeEngine events but getting error
dataWriter.advise(DWriteEngine2Events.class, new DWriteEngine2EventsReceiver());
But here I'm getting an error in runtime:
java.util.concurrent.CompletionException: com4j.ExecutionException: com4j.ComException: 80040200 (Unknown error) : .\invoke.cpp:517
The DWriteEngine2EventsReceiver class is implementation of the DWriteEngine2Events interface:
public class DWriteEngine2EventsReceiver implements DWriteEngine2Events {
#DISPID(7)
#Override
public void update(Com4jObject object, Com4jObject progress) {
System.out.println("DWriteEngine2EventsReceiver.update");
}
#Override
public int getPtr() {
System.out.println("DWriteEngine2EventsReceiver.getPtr()");
return 0;
}
#Override
public long getPointer() {
System.out.println("DWriteEngine2EventsReceiver.getPointer()");
return 0;
}
// all other methods of DWriteEngine2Events COM interface defined similarly
I expected that DWriteEngine2EventsReceiver.update method should receive event notification.
What I'm doing wrong?
PS. here the full method code: https://github.com/vzateychuk/iso-writer/blob/master/desktop/src/main/java/ru/vez/iso/desktop/burn/BurnSrvImpl.java#L101 (exception in line 125)

Getting LiveStreamManager error -3 in DJI Mobile SDK when trying to stream to custom RTMP?

I'm trying to implement a app that sends live video from drone to my custom rtmp server. When I use de LiveStreamManager from DJI Mobile SDK it gives me error code -3, and the stream do not start. How can I use this API?
My app registers successfully, I can setup missions, and get telemetry from drone. But when I try to use the LiveStreamManeger it won't work no matter what. Even by implementing exactly the way it is implemented in Sample Code, it does not work. Documentation in DJI API reference seems to be missing a few methods as well.
Here is my implementation
private void setupLiveStream() {
DJISDKManager.getInstance().getLiveStreamManager().registerListener(listener);
initListener();
DJISDKManager.getInstance().getLiveStreamManager().setAudioStreamingEnabled(false);
DJISDKManager.getInstance().getLiveStreamManager().setVideoSource(LiveStreamManager.LiveStreamVideoSource.Primary);
liveURL = "rtmp://mycustomrtmp.com/drone/live_testDJI";
}
private void initListener() {
listener = new LiveStreamManager.OnLiveChangeListener() {
#Override
public void onStatusChanged(int i) {
setResultToToast("status changed : " + i);
}
};
}
private void StartStreaming(){
if (!isLiveStreamManagerOn()) {
return;
}
if (DJISDKManager.getInstance().getLiveStreamManager().isStreaming()) {
setResultToToast("already started the Stream!");
return;
}
new Thread() {
#Override
public void run() {
DJISDKManager.getInstance().getLiveStreamManager().setLiveUrl(liveURL);// + vehicleID);
int result = DJISDKManager.getInstance().getLiveStreamManager().startStream();
DJISDKManager.getInstance().getLiveStreamManager().setStartTime();
setResultToToast("LiveStream Start: " + result +
"\n isVideoStreamSpeedConfigurable:" + DJISDKManager.getInstance().getLiveStreamManager().isVideoStreamSpeedConfigurable() +
"\n isLiveAudioEnabled:" + DJISDKManager.getInstance().getLiveStreamManager().isLiveAudioEnabled());
}
}.start();
}
I always get a return code -3. When I use the sample code I can get it to work. The only diference is then I call the function isVideoStreamSpeedConfigurable(), it returns true on my code, and false on sample code. But I did not see where I can set this thing to false. How should I implement LiveStreamingManager?
Answering my own question...
I've managed to solve the issue. Apparently, to be able to use the LiveStreamManager you must first call the function VideoFeeder.getPrimaryVideoFeed() somewhere in your code or it will give error code -3.
Using the Sample Code there is a class in internal.utils.VideoFeedView that can be used to this purpose
I have first declared a private property VideoFeedView.
Then on my class constructor I call the initUI function.
private VideoFeedView primaryVideoFeed;
private void initUI() {
primaryVideoFeed.registerLiveVideo(VideoFeeder.getInstance().getPrimaryVideoFeed(),true);
startStreaming();
}
I don't know if I just was lucky, but for me, the following code solved my problem. I didn't have any need for anything more, like VideoFeedView. What is the reason for using that?
I running on a mavic 2 pro and streaming 30fps 720p to youtube.
private LiveStreamManager l;
public int live_streaming_start(String live_url){
Log.d("MavicMax", "LiveStream:live_streaming_start:" + live_url);
l = DJISDKManager.getInstance().getLiveStreamManager();
l.registerListener((x)->{Log.d("MavicMax", "LiveStream callback:" + x);});
l.setVideoSource(LiveStreamManager.LiveStreamVideoSource.Primary);
l.setVideoEncodingEnabled(true);
l.setLiveUrl(live_url);
int r = 0;
r = l.startStream();
return r;
}

Sendbird Remove Member from a Channel or group

I am using Sendbird SDK for a chat in my application following the steps through official documentation. Everything is working fine but recently I wanted to implement a functionality in which I wanted to give access to admin to remove a member from the group. But, while going through the official documentation, I came to know there is no such functionality or method provided in SendBird. So, is there any workaround or better way to do the same.
Some time has passed since this question was posted, but here are the official guides for the ban functionality.
Group Channel
if (groupChannel.getMyRole() == Member.Role.OPERATOR) {
groupChannel.banUser(USER, DESCRIPTION, SECONDS, new GroupChannel.GroupChannelBanHandler() {
#Override
public void onResult(SendBirdException e) {
if (e != null) { // Error.
return;
}
// TODO: Custom implementation for what should be done after banning.
}
});
}
Open Channel
if (openChannel.isOperator(SendBird.getCurrentUser())) {
openChannel.banUser(USER, SECONDS, new OpenChannel.OpenChannelBanHandler() {
#Override
public void onResult(SendBirdException e) {
if (e != null) { // Error.
return;
}
// TODO: Custom implementation for what to do after banning.
}
});
}
Please keep in mind that an user should be an operator to ban or unban a user.

Deal with server sent event on client side GWT

I need to implement front-end for Server-Sent-Event. I use GWT, and i can not find any solution to create a listener for SSE. I need to push the data from server and to receive it on client every time hen data was changed. So for now i have a something like this:
private void method() {
final EventSource eventSource = EventSource.newEventSourceIfSupported();
if (null != eventSource) {
eventSource.setListener(this);
eventSource.open(GWT.getHostPageBaseURL() + "rest/myresource");
}
}
#Override
public void onOpen(EventSource eventSource) {
Window.alert("Open");
}
#Override
public void onClose(EventSource eventSource) {
Window.alert("onClose");
}
#Override
public void onMessage(EventSource eventSource, String lastEventId, String type, String data) {
Window.alert("lastEventId: " + lastEventId);
Window.alert("type: " + type);
Window.alert("data: " + data);
}
#Override
public void onError(EventSource eventSource) {
Window.alert("onError");
}
my class implements EventSourceListener
But it does not work. Actually this code reacting only when connection is opened, but it is impossible to receive any message from server. Do somebody know how to deal the issue with receiving data on client using GWT?
There are so many methods exist in GWT for push back services like a GWT Event Services enter link description here
In order for the server to initiate a request to the client, you will need to use WebSockets, and experimental HTML5 feature currently only supported by Chrome.
Or, to simulate this kind of interaction, you can use Comet (long-polling), made available in GWT by the rocket-gwt project.

UPNP/DLNA Control Point

I'm working on an android UPnP/DLNA app. I have a control point working where I can stream files from media server to renderer. I can pause/play and stop the file during playback but I cannot seem to figure out how to integrate a seekbar into the control point to show the progress of the playing file and be able to interact with the seekbar. I am using the Cling Java library to create the app. If anyone has any examples that could help me I would really appreciate it.
Thanks
I've tried to implement the SubscriptionCallback example and subscribe to LastChange
SubscriptionCallback callback = new SubscriptionCallback(service, 600) { // Timeout in seconds
public void established(GENASubscription sub) {
System.out.println("Established: " + sub.getSubscriptionId());
}
#Override
public void failed(GENASubscription sub, UpnpResponse response, Exception ex) {
System.err.println(
createDefaultFailureMessage(response, ex)
);
}
#Override
public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {
// Reason should be null, or it didn't end regularly
}
public void eventReceived(GENASubscription sub) {
System.out.println("Event: " + sub.getCurrentSequence().getValue());
try {
lastChange = new LastChange(
new AVTransportLastChangeParser(),
sub.getCurrentValues().get("LastChange").toString()
);
} catch (Exception ex) {
log.warning("Error parsing LastChange event content: " + ex);
return;
}
Map<String, StateVariableValue> values = sub.getCurrentValues();
StateVariableValue status = values.get("Status");
System.out.println("Status is: " + status.toString());
}
public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {
System.out.println("Missed events: " + numberOfMissedEvents);
}
#Override
protected void failed(GENASubscription arg0,
UpnpResponse arg1, Exception arg2, String arg3) {
}
};
upnpService.getControlPoint().execute(callback);
Then I try to get the duration of the current playing track:
System.out.println("Duration: "+lastChange.getEventedValue(0, AVTransportVariable.CurrentTrackDuration.class).getValue());
but this returns a NullPointerException.
Any ideas???????
************UPDATE***********
I have been trying to implement Seek() but have not had success.
I have my seekbar and listener but it it keeps failing when I drag the seekbar to a new position.
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
#Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2)
{
Log.i("SEEKTIME", "time:" + arg1);
upnpService.getControlPoint().execute(new Seek(service, SeekMode.REL_TIME, arg0.toString())
{
#Override
public void success(ActionInvocation invocation)
{
//super.success(invocation);
Log.i("SEEKSUCCESS", "success seek");
}
#Override
public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2)
{
Log.i("SEEKFAIL", "fail seek");
}
});
}
Any suggestions why this would be failing
You must poll the renderer for this kind of information (see AVTransport spec chapter 2.3.1). The spec encourages polling every second, but you can easily jam up a real hardware renderer (for which DLNA is still rather a fashionable pain in the a** than a vital part of the design). Our established practice is to send GetPositionInfo() request every 2-3 seconds and treat the returned RelativeTimePosition value only as an adjustment to locally running timer. For the seekbar sizing you also need the total length of current media. Ideally the renderer will tell you automatically when you subscribe to AVTransport.LastChange. I don't know Cling specifically but a quick look shows promising example in controlpoint.SubscriptionCallback. Unfortunately with real devices, LastChange often doesn't tell you anything much. Either the values are not there at all or have a constant inert value. So you will need to poll the GetMediaInfo() again and use MediaDuration value.
As for interaction, Seek() is your friend, ideally with parameters of Unit = REL_TIME and Target = your desired time offset. Be aware that a real world renderer may not be supporting this unit (mode) of seeking. Perhaps it supports only TRACK_NR in which case the seekbar is essentialy read-only for you. Again Cling should be able to tell you allowed values of A_ARG_TYPE_SeekMode for the particular renderer.

Categories