I've searched for hours and can't find an answer (lots of unanswered questions on SO, among other things).
My current code
/**
* Use when the server has determined how many Alerts are situated inside
* a single Monitored Zone of a user.
*
* Documentation:
* https://firebase.google.com/docs/cloud-messaging/admin/send-messages
*
* #param registrationToken tokens of the devices the notif is sent to
* #param mzName name of the Monitored Zone (can be its ID)
* #param nbrAlertes number of alerts detected inside the MZ
*/
public static void sendMzLiveAlertNotif(ArrayList<String> registrationToken,
String mzName, int nbrAlertes) {
if(registrationToken.size() == 0 || nbrAlertes == 0 || mzName.isEmpty())
return;
registrationToken.forEach(token -> {
// See documentation on defining a message payload.
Message message = Message.builder()
.putData("title", NotifType.NEW_LIVE_ALERT.getTitle())
.putData("body", "\"" + mzName + "\" contient " + nbrAlertes + " alertes.")
.putData("tag", mzName)
.putData("nbrAlerts", nbrAlertes+"")
.setToken(token)
.build();
try {
// Send a message to the device.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
} catch (Exception e) {
e.printStackTrace();
}
});
}
This worked perfectly, until I wanted to add a lifespan to my notifications. I am still trying to figure out what is the proper way to do so with Java.
My question
I'm wondering how I am supposed to impose a 30 hours lifespan to my message (and also why it works without me using the setAndroidConfig method that Google seems to use).
My server is coded in Java, and the notifications are pushed to an Android application.
My initial thought was to go for:
Message message = Message.builder()
.putData("title", NotifType.NEW_LIVE_ALERT.getTitle())
.putData("body", "\"" + mzName + "\" contient " + nbrAlertes + " alertes.")
.putData("tag", mzName)
.putData("nbrAlerts", nbrAlertes+"")
.setToken(token)
.setAndroidConfig(AndroidConfig.builder()
.setTtl(3600 * 30) // 30 hours ?
.build())
.build();
... but after seeing how Google uses the AndroidConfig for the whole thing, I'm wondering if I should too.
Google Documentation
The only examples I can find are from Google themselves. Here is an example:
#Test
public void testAndroidMessageWithoutNotification() throws IOException {
Message message = Message.builder()
.setAndroidConfig(AndroidConfig.builder()
.setCollapseKey("test-key")
.setPriority(Priority.HIGH)
.setTtl(10)
.setRestrictedPackageName("test-pkg-name")
.putData("k1", "v1")
.putAllData(ImmutableMap.of("k2", "v2", "k3", "v3"))
.build())
.setTopic("test-topic")
.build();
Map<String, Object> data = ImmutableMap.<String, Object>of(
"collapse_key", "test-key",
"priority", "high",
"ttl", "0.010000000s", // 10 ms = 10,000,000 ns
"restricted_package_name", "test-pkg-name",
"data", ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3")
);
assertJsonEquals(ImmutableMap.of("topic", "test-topic", "android", data), message);
}
Do you see the .setTtl(10)and the "ttl", "0.010000000s", // 10 ms = 10,000,000 ns parts? It confuses me. Their documentation says (emphasis is mine):
time_to_live : Optional, number : This parameter specifies how long (in seconds) the message should be kept in FCM storage if the
device is offline. The maximum time to live supported is 4 weeks, and
the default value is 4 weeks. For more information, see Setting the
lifespan of a
message.
The link they tell us to read says:
On Android and Web/JavaScript, you can specify the maximum lifespan of
a message. The value must be a duration from 0 to 2,419,200 seconds
(28 days), and it corresponds to the maximum period of time for which
FCM stores and attempts to deliver the message. Requests that don't
contain this field default to the maximum period of four weeks.
They clearly want the thing to be in seconds. Yet their tests show usage of milliseconds ?! It is frustrating to find so many examples in JavaScript, and almost nothing in Java within their documentation!
In itself, one can also find this contradictory documentation:
public AndroidConfig.Builder setTtl (long ttl)
Sets the time-to-live duration of the message in milliseconds.
A good case of confusing documentation.
You should go with ms, so for 30 hours you would get something like this:
Message message = Message.builder()
.putData("title", NotifType.NEW_USER_ALERT.getTitle())
.putData("body", "\"" + mzName + "\" contient " + nbrAlertes + " alertes.")
.putData("tag", mzName)
.putData("nbrAlerts", nbrAlertes+"")
.setToken(token)
.setAndroidConfig(AndroidConfig.builder()
.setTtl(30*3600*1000) // 30 hours
.build())
.build();
I am trying to fetch the fired alerts using the splunk java sdk. But i am not able to get any reference. Here is the code snippet i have and it is not fetching me any results.
FiredAlertGroupCollection firedAlertGroups = service.getFiredAlertGroups();
System.out.println("Fired Alert : " + firedAlertGroups.size());
for (FiredAlertGroup entity : firedAlertGroups.values()) {
EntityCollection<FiredAlert> alerts = entity.getAlerts();
for (FiredAlert alert : alerts.values()) {
System.out.println("alerts >>>> " +alert.getName() +": " + alert.getSavedSearchName()+": " + alert.getTitle());
}
}
Is there a way, i can filter the alerts fired in the last 24 hours etc.
Please help me on the same.
Here I am trying to get ASSET details in simple java
Here is the code
MXSession session = MXSession.getSession();
session.setHost("localhost:13400/MXServer");
session.setUserName(user);
session.setPassword(pwd);
session.connect();
The connection was successful.
Then I tried to get the asset details with the code
MboSetRemote assetMboSet = session.getMboSet("ASSET");
assetMboSet.setOrderBy("ASSETNUM");
MboRemote assetMbo;
for(int j=0; ((assetMbo = assetMboSet.getMbo(j)) != null); j++)
{
String assetNum = assetMbo.getString("ASSETNUM");
String location = assetMbo.getString("LOCATION");
String desc = assetMbo.getString("DESCRIPTION");
System.out.println(assetNum + " - " + location + " - " + desc);
}
it is giving me the error and could not proceed further in the line
MboSetRemote assetMboSet = session.getMboSet("ASSET");
saying
Exception in thread "main" psdi.util.MXSystemException: system#unknownerror
at psdi.util.RMISession.getMboSet(RMISession.java:330)
Please suggest me how to proceed
My friend I just tried your code scripth and it works fine, here is a snapshot of my environment which shows your work.
This problem may occur, If the admin mode is on OR you need to change take a look at sessions, to do that.
you can go to the users application.
Select action > manage sessions.
You can view users who are currently logged into the system.
You can log out a user from the system or log out and block a user from the system.
You can see the login history of users.
I am struggling for a couple of hours now on how to link a discid to a musicbrainz mbid.
So, using dietmar-steiner / JMBDiscId
JMBDiscId discId = new JMBDiscId();
if (discId.init(PropertyFinder.getProperty("libdiscid.path")))
{
String musicBrainzDiscID = discId.getDiscId(PropertyFinder.getProperty("cdrom.path"));
}
or musicbrainzws2-java
Disc controller = new Disc();
String drive = PropertyFinder.getProperty("cdrom.path");
try {
DiscWs2 disc =controller.lookUp(drive);
log.info("DISC: " + disc.getDiscId() + " match: " + disc.getReleases().size() + " releases");
....
I can extract a discid for freedb or musicbrainz easily (more or less), but I have not found a way on calculating the id I that I need to download cover art via the CoverArtArchiveClient from last.fm.
CoverArtArchiveClient client = new DefaultCoverArtArchiveClient();
try
{
UUID mbid = UUID.fromString("mbid to locate release");
fm.last.musicbrainz.coverart.CoverArt coverArt = client.getByMbid(mbid);
Theoretically, I assume, I could you the data collected by musicbrainzws2-java to trigger a search, and then use the mbid from the result ... but that cannot be the best option to do.
I am happy about any push into the right direction...
Cheers,
Ed.
You don't calculate the MBID. The MBID is attached on every entity you retrieve from MusicBrainz.
When getting releases by DiscID you get a list. Each entry is a release and has an MBID, accessible with getId():
for (ReleaseWs2 rel : disc.getReleases()){
log.info("MBID: " + rel.getId() + ", String: " + rel.toString());
}
You then probably want to try the CoverArtArchive (CAA) for every release and take the first cover art you get.
Unfortunately I don't know of any API documentation for musicbrainzws2 on the web. I recommend running javadoc on all source files.
I’m using FreePBX with Asterisk’s Java API.
For the moment, I’m able to display all my SIP peers with their respective states:
public void onManagerEvent(ManagerEvent event)
{
// Look if the event is a IP phone (Peer entry)
if(event instanceof PeerEntryEvent)
{
PeerEntryEvent ev = (PeerEntryEvent)event;
// Get the user extension
peer = ev.getObjectName();
// Add to the array
peersName.add(peer);
}
}
I’m able to display the phone number and name of both callers when a channel is open:
private String GetExtensionPeer(String extension)
{
for (AsteriskChannel e : channels)
if (e.number.equals(extension) && e.bridge != null )
for (AsteriskChannel channel : channels)
if (z.channel.equals(e.bridge))
return " with " + channel.number + " - " + channel.name;
return "";
}
But now, I would like to display the name of my extensions without a channel connection.
In FreePBX's panel, it's look like :
In freepbx you can get list of extensions from asterisk db. To see info, do
asterisk -rx "database show"
To get info use manager action "command" with DBGET.
Other option - got that info from freepbx's mysql db.