Asterisk 11.4.0
Asterisk-java: 1.0.0.CI-SNAPSHOT
I've try to run this code:
import org.asteriskjava.live.AsteriskChannel;
import org.asteriskjava.live.AsteriskQueue;
import org.asteriskjava.live.AsteriskQueueEntry;
import org.asteriskjava.live.internal.AsteriskAgentImpl;
import org.asteriskjava.live.AsteriskServer;
import org.asteriskjava.live.AsteriskServerListener;
import org.asteriskjava.live.DefaultAsteriskServer;
import org.asteriskjava.live.ManagerCommunicationException;
import org.asteriskjava.live.MeetMeRoom;
import org.asteriskjava.live.MeetMeUser;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
public class HelloLiveEverything implements AsteriskServerListener, PropertyChangeListener
{
private AsteriskServer asteriskServer;
public HelloLiveEverything()
{
asteriskServer = new DefaultAsteriskServer("localhost", "manager", "password");
}
public void run() throws ManagerCommunicationException
{
// listen for new events
asteriskServer.addAsteriskServerListener(this);
// add property change listeners to existing objects
for (AsteriskChannel asteriskChannel : asteriskServer.getChannels())
{
System.out.println(asteriskChannel);
asteriskChannel.addPropertyChangeListener(this);
}
}
public void onNewAsteriskChannel(AsteriskChannel channel)
{
System.out.println(channel);
channel.addPropertyChangeListener(this);
}
public void onNewMeetMeUser(MeetMeUser user)
{
System.out.println(user);
user.addPropertyChangeListener(this);
}
public void onNewQueueEntry(AsteriskQueueEntry user)
{
System.out.println(user);
user.addPropertyChangeListener(this);
}
public void onNewAgent(AsteriskAgentImpl user)
{
System.out.println(user);
user.addPropertyChangeListener(this);
}
public void propertyChange(PropertyChangeEvent propertyChangeEvent)
{
System.out.println(propertyChangeEvent);
}
public static void main(String[] args) throws Exception
{
HelloLiveEverything helloLiveEverything = new HelloLiveEverything();
helloLiveEverything.run();
while (true) {
}
}
}
When executed, connectios is OK. This code show me current channels but never show me new channels when callers make a calls.
I need to catch the events when new asterisk channels are opening.
What I made wrong?
Thank you
Try This:
Your Class HelloLiveEverything should implement ManagerEventListener
then override the onManagerEvent method
#Override
public void onManagerEvent(ManagerEvent event) {
String event_name = event.getClass().getSimpleName();
if (event_name.equals("DialEvent")) {
DialEvent e = (DialEvent) event;
System.out.println(e.getCallerIdNum());//caller number
System.out.println(e.getDestination());//Called number
//do something here
}
}
edit asterisk manager.conf :
[manager]
secret = password
deny=0.0.0.0/0.0.0.0
permit=209.16.236.73/255.255.255.0; change this ip with one your java app is using permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user,originate; add full permission
write = system,call,log,verbose,command,agent,user,originate; add full permission
Related
When the Task includes 2 lines opening a stream and closing it, the Task returns correctly. Its succeed method runs. But the Service' setOnSucceeded method does not run. Why?
When the 2 lines about the streaming opening and closing are commented out in the Task, we do get the expected behavior: System.out.println("in the succeed method of the Service") does print.
The Main method:
package Test;
import javafx.application.Application;
import javafx.concurrent.Worker;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
MyService pluginUpdateService = new MyService();
pluginUpdateService.setOnFailed(e -> {
System.out.println("task failed");
});
pluginUpdateService.setOnSucceeded(e -> {
System.out.println("in the succeed method of the Service"); // this does not print, when MyTask opens the stream (see code of MyTask)
});
// launching the service
if (pluginUpdateService.getState() == Worker.State.READY) {
pluginUpdateService.start();
}
}
}
The service MyService
package Test;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
public class MyService extends Service {
public MyService() {
}
#Override
protected Task createTask() {
Task updater = new MyTask();
return updater;
}
}
The task MyTask:
package Test;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javafx.concurrent.Task;
public class MyTask extends Task {
public MyTask() {
}
#Override
protected Void call() throws MalformedURLException, IOException {
InputStream in;
URL url = new URL("https://clementlevallois.net");
in = url.openStream(); // when this line is commented out, the Service does trigger its setOnSucceeded method as expected
in.close(); // when this line is commented out, the Service does trigger its setOnSucceeded method as expected
System.out.println("about to return from the call method of the Task");
return null;
}
#Override
protected void succeeded() {
super.succeeded();
System.out.println("succeeded - sent from the succeeded method of the Task");
}
#Override
protected void cancelled() {
super.cancelled();
System.out.println("cancelled");
updateMessage("Cancelled!");
}
#Override
protected void failed() {
super.failed();
System.out.println("failed");
updateMessage("Failed!");
}
}
I am using the below code sample where I am calling the cancelWF method to cancel the execution of workflow. The onCatch method is successfully invoked with the RuntimeException("Simply cancel"), but on the Amazon SWF console the WF does not end immediately, it waits will timeout and ends with a WorkflowExecutionTerminated event.
The whole project is available here if you want more info.
package aws.swf;
import aws.swf.common.Constants;
import aws.swf.common.DelayRequest;
import aws.swf.common.MyActivityClient;
import aws.swf.common.MyActivityClientImpl;
import aws.swf.common.MyWorkflow;
import aws.swf.common.SWFClient;
import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflow;
import com.amazonaws.services.simpleworkflow.flow.WorkflowWorker;
import com.amazonaws.services.simpleworkflow.flow.annotations.Asynchronous;
import com.amazonaws.services.simpleworkflow.flow.core.Promise;
import com.amazonaws.services.simpleworkflow.flow.core.TryCatch;
import java.util.concurrent.CancellationException;
public class D_CancelWorkflow implements MyWorkflow {
private TryCatch tryCatch;
private final MyActivityClient activityClient = new MyActivityClientImpl();
#Override
public void sum() {
tryCatch = new TryCatch() {
#Override
protected void doTry() throws Throwable {
System.out.printf("[WF %s] Started exec\n", D_CancelWorkflow.this);
Promise<Integer> result = activityClient.getNumWithDelay(new DelayRequest("req1", 1));
cancelWF(result);
newDelayRequest(result);
}
#Override
protected void doCatch(Throwable e) throws Throwable {
if (e instanceof CancellationException) {
System.out.printf("[WF %s] Cancelled With message [%s]\n",
D_CancelWorkflow.this, e.getCause().getMessage());
} else {
e.printStackTrace();
}
rethrow(e);
}
};
}
#Asynchronous
private void newDelayRequest(Promise<Integer> num) {
activityClient.getNumWithDelay(new DelayRequest("req2", 1));
}
#Asynchronous
private void cancelWF(Promise<Integer> ignore) {
System.out.printf("[WF %s] Cancelling WF\n", D_CancelWorkflow.this);
this.tryCatch.cancel(new RuntimeException("Simply cancel"));
}
public static void main(String[] args) throws Exception {
AmazonSimpleWorkflow awsSwfClient = new SWFClient().getClient();
WorkflowWorker workflowWorker =
new WorkflowWorker(awsSwfClient, Constants.DOMAIN, Constants.TASK_LIST);
workflowWorker.addWorkflowImplementationType(D_CancelWorkflow.class);
workflowWorker.start();
}
}
This is the event history for one of my execution,
So I have coded the following code:
package com.ste999.firstplugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class Main extends JavaPlugin {
public Main() {}
#Override
public void onEnable() {
getLogger().info("Stefan's first plugin enabled");
}
private volatile boolean chatEnabled = true;
#EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player pli = event.getPlayer();
if (!chatEnabled) {
if (!pli.hasPermission("ste.chat.bypass")) {
pli.sendMessage("§4Chat is disabled!");
event.setCancelled(true);
//return true;
}
}
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
Player p = (Player)sender;
if (cmd.getName().equalsIgnoreCase("mutechat")) {
chatEnabled = !chatEnabled;
sender.sendMessage(chatEnabled ? "§aUnmuted the chat" : "§aMuted the chat");
return true;
}
return true;
}
#Override
public void onDisable() {
getLogger().info("Stefan's first plugin disabled");
}
}
with the following plugin.yml:
name: Stefans_Helper
main: com.ste999.firstplugin.Main
version: 1.0
load: startup
description: this is my first plugin
commands:
mutechat:
description: mute the chat
usage: /<command>
When I use this plugin in my Minecraft server, it shows up and if I do /mutechat it says Muted the chat en when I do /mutechat again it says Unmuted the chat
What I expect this code to do is when the chat is "Muted" no users can talk, unless they have the ste.chat.bypass permission node.
But a user without op and the ste.chat.bypass can still talk in chat after someone did /mutechat and the chat said Muted the chat.
I've tried putting getServer().getPluginManager().registerEvents(this, this); in the public void onEnable but then I get an error in eclipse that says: The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (Main, Main)
Uhh help pls
Your events class (I seriously recommend a new class for this) needs to implement the Listener interface. Only then can you register it.
So I was able to get the mutechat function with the following code:
package com.ste999.events;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
//import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
public class Main extends JavaPlugin implements Listener{
public static boolean chatMuted = false;
#Override
public void onEnable()
{
getLogger().info("events tester enabled!");
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(this, (this));
}
#Override
public void onDisable()
{
getLogger().info("events tester disabled!");
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
Player player = (Player)sender;
if (cmd.getName().equalsIgnoreCase("mutechat")) {
if (player.hasPermission("ste999.chat.mute")) {
if(chatMuted == false) {
Bukkit.broadcastMessage("§aThe chat has been disabled!");
chatMuted = true;
}
else {
if(chatMuted == true) {
Bukkit.broadcastMessage("§aThe chat has been enabled!");
chatMuted = false;
}
}
} else {
if (!player.hasPermission("ste999.chat.mute")) {
player.sendMessage("§4You can't mute the chat silly!");
}
}
}
return false;
}
#EventHandler
public void OnChat(AsyncPlayerChatEvent event)
{
Player pli = event.getPlayer();
if (chatMuted == true) {
if (!pli.hasPermission("ste999.chat.bypass")) {
event.setCancelled(true);
pli.sendMessage("§4The chat has been disabled");
} else {
if (pli.hasPermission("ste999.chat.bypass")) {
event.setCancelled(false);
}
}
}
}
}
I needed to register the events but getServer().getPluginManager().registerEvents(this, this) didn't work for me so I needed to do it the way I did it in the code in onEnable and there where a few other problems
Problem:
Receiving a stream of command line warnings as video plays - deprecated pixel format used, make sure you did set range correctly
Question:
How can I stop the warnings from happening or being displayed?
Update - Fixed:
The solution was too override the logging callback and don't do anything in the logging call method. FFmpeg logging is then disabled.
The reason for the message from FFmpeg is because it is grabbing frames from an old video format so is unavoidable if playing older videos.
NOTE:
This solution completely disables all output from FFmpeg. Even FFmpeg errors are muted.
Code below (just frame grabbing, not timed playback).
package test.javacv;
import java.io.File;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.CustomLogCallback;
public class TestPlay implements Runnable {
private static String video_loc = null;
private static CanvasFrame canvas = new CanvasFrame("Test JavaCV player");
public static void main(String[] args) { new Thread(new TestPlay(args[0])).start(); }
static {
CustomLogCallback.set();
}
public void run() { play_video(video_loc); }
public TestPlay(String loc) {
video_loc = loc;
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
public static final void play_video(String vid_loc) {
try {
File file = new File(vid_loc);
FFmpegFrameGrabber ffmpeg_fg = new FFmpegFrameGrabber(file.getAbsolutePath());
Frame frm;
ffmpeg_fg.setAudioChannels(0);
ffmpeg_fg.start();
for(;;)
if((frm = ffmpeg_fg.grab()) != null) canvas.showImage(frm);
else {
ffmpeg_fg.setTimestamp(0);
break;
}
ffmpeg_fg.stop();
} catch(Exception ex) { ex("play_video vid_loc:" + vid_loc, ex); }
}
public static final void ex(String txt, Exception ex) {
System.out.println("EXCEPTION: " + txt + " stack..."); ex.printStackTrace(System.out); }
}
Logging class
// custom logger to override all logging output
package org.bytedeco.javacv;
import org.bytedeco.javacpp.BytePointer;
import static org.bytedeco.javacpp.avutil.LogCallback;
import static org.bytedeco.javacpp.avutil.setLogCallback;
public class CustomLogCallback extends LogCallback {
static final CustomLogCallback instance = new CustomLogCallback();
public static CustomLogCallback getInstance() { return instance; }
public static void set() { setLogCallback(getInstance()); }
#Override
public void call(int level, BytePointer msg) {}
}
You can adjust the logging level in JavaCV using org.bytedeco.javacpp.avutil.av_log_set_level().
calling avutil.av_log_set_level(avutil.AV_LOG_QUIET); will probably get you what you want.
I have a play framework that uses the play actor integration to reference and communicate with a remote akka system. Looks like I am not getting the remote referencing right. First the remote akka implements the bootable interface and It has a master node that creates a child actor system.
the play actor system then references the remote system. the code snippets are presented below.
this is the Play framework node that creates the local actor system
public void connectMaster (final String classname)
{
localActor.tell(classname);
}
public void connectMaster ()
{
//localActor.tell(getByte(new Coordinates()));
}
public void connectMaster (final WebSocket.In<JsonNode> in, final WebSocket.Out<JsonNode> out )
{
in.onMessage(new Callback<JsonNode>() {
public void invoke(JsonNode event) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
#SuppressWarnings("unchecked")
Map<String,ArrayList<Object>> jsonMap = mapper.readValue(event, Map.class);
GesturePoints gp = new GesturePoints();
gp.setPoints(jsonMap);
localActor.tell(gp);
}
}); }
this is the local Actor system in play framework
package controllers;
import Com.RubineEngine.GesturePoints.*;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
public class LocalActor extends UntypedActor {
/**
*
*/
ActorRef masterActor; // = getContext().actorFor("akka://MasterNode#127.0.0.1:2552/user/masterActor");
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
#Override
public void onReceive(Object arg) throws Exception {
System.out.println(" Local Actor 1");
if(arg instanceof GesturePoints)
{ System.out.println(" local Actor 2");
masterActor.tell(arg , getSelf());
System.out.println(" Local Actor 3");}
else
{unhandled(arg);}
}
public void preStart()
{
masterActor = getContext().actorFor("akka://MasterNode#127.0.0.1:2552/user/masterActor");
}
}
this is the remote akka system master Node that creates the master actor
package Rubine_Cluster;
import java.util.Arrays;
import com.typesafe.config.ConfigFactory;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.kernel.Bootable;
/**
* Hello world!
*
*/
public class MasterNode implements Bootable
{
final ActorSystem system;
ActorRef masterActor;
public MasterNode() {
//Create a child actor of this actor upon initialization
system = ActorSystem.create("MasterNode", ConfigFactory.load()
.getConfig("masterNode"));
masterActor = system.actorOf(new Props(MasterActor.class),"masterActor");
}
public void startup() {
}
public void shutdown() {
system.shutdown();
}
}
this is the remote actor system created by the MasterNode
public class MasterActor extends UntypedActor {
/**
*
*/
ActorSystem system = ActorSystem.create("container");
ActorRef worker1;
//public MasterActor(){}
#Override
public void onReceive(Object message) throws Exception {
System.out.println(" Master Actor 5");
if(message instanceof GesturePoints)
{ //GesturePoints gp = (GesturePoints) message;
System.out.println(" Master Actor 1");
try { worker1.tell(message, getSelf());
System.out.println(" Master Actor 2");
} catch (Exception e) {
getSender().tell(new akka.actor.Status.Failure(e), getSelf());
throw e;
}
}
else{ unhandled(message);}
}
public void preStart()
{
worker1 = getContext().actorFor("akka://WorkerNode#127.0.0.1:2553/user/workerActor");
}
}
I think I got the referencing wrong or probably were to send the message any suggestion is welcome