I'm a newbie to Silverlight.
Recently i downloaded a solution which records an Audio from the webpage present under silvoicerecordupload.codeplex.com/
What i'm trying to do is, The recording should stop after 5 mins.
I found some articles like:
Dispatcher class
Timer class
I tried using the Dispatcher class, it just has Start() and Stop() methods,
but i cannot keep track of time that is being spent on the recording.
Please help me regarding this.
Thanks,
Sachin
I haven't checked the codeplex project but I'm assuming you have means of starting and stopping the recording via two methods. The timer will call the StopRecording() method as soon as the time specified by recordingTimeInMilis is used up.
public class TimedRecorder
{
private const int recordingTimeInMilis = 5 * 60 * 1000;
private Timer m_timer;
public void StartRecording()
{
m_recorder.Start();
m_timer = new Timer(
StopRecording, null, recordingTimeInMilis, Timeout.Infinite);
}
public void StopRecording()
{
m_recorder.Stop();
m_timer.Dispose();
m_timer = null;
}
}
Related
In order to improve the performance of data process, we store events to a map and do not process them untill event count reaches 100.
in the meantime, start a timer in open method, so data is processed every 60 seconds
this works when flink version is 1.11.3,
after upgrading flink version to 1.13.0
I found sometimes events were consumed from Kafka continuously, but were not processed in RichFlatMapFunction, it means data was missing.
after restarting service, it works well, but several hours later the same thing happened again.
any known issue for this flink version? any suggestions are appreciated.
public class MyJob {
public static void main(String[] args) throws Exception {
...
DataStream<String> rawEventSource = env.addSource(flinkKafkaConsumer);
...
}
public class MyMapFunction extends RichFlatMapFunction<String, String> implements Serializable {
#Override
public void open(Configuration parameters) {
...
long periodTimeout = 60;
pool.scheduleAtFixedRate(() -> {
// processing data
}, periodTimeout, periodTimeout, TimeUnit.SECONDS);
}
#Override
public void flatMap(String message, Collector<String> out) {
// store event to map
// count event,
// when count = 100, start data processing
}
}
You should avoid doing things with user threads and timers in Flink functions. The supported mechanism for this is to use a KeyedProcessFunction with processing time timers.
I have the following scenario: suppose there are 20 sensors which are sending me streaming feed. I apply a keyBy (sensorID) against the stream and perform some operations such as average etc. This is implemented, and running well (using Flink Java API).
Initially it's all going well and all the sensors are sending me feed. After a certain time, it may happen that a couple of sensors start misbehaving and I start getting irregular feed from them e.g. I receive feed from 18 sensors,but 2 don't send me feed for long durations.
We can assume that I already know the fixed list of sensorId's (possibly hard-coded / or in a database). How do I identify which two are not sending feed? Where can I get the list of keyId's to compare with the list in database?
I want to raise an alarm if I don't get a feed (e.g 2 mins, 5 mins, 10 mins etc. with increasing priority).
Has anyone implemented such a scenario using flink-streaming / patterns? Any suggestions please.
You could technically use the ProcessFunction and timers.
You could simply register timer for each record and reset it if You receive data. If You schedule the timer to run after 5 mins processing time, this would basically mean that If You haven't received the data it would call function onTimer, from which You could simply emit some alert. It would be possible to re-register the timers for already fired alerts to allow emitting alerts with higher severity.
Note that this will only work assuming that initially, all sensors are working correctly. Specifically, it will only emit alerts for keys that have been seen at least once. But from your description it seems that It would solve Your problem.
I just happen to have an example of this pattern lying around. It'll need some adjustment to fit your use case, but should get you started.
public class TimeoutFunction extends KeyedProcessFunction<String, Event, String> {
private ValueState<Long> lastModifiedState;
static final int TIMEOUT = 2 * 60 * 1000; // 2 minutes
#Override
public void open(Configuration parameters) throws Exception {
// register our state with the state backend
state = getRuntimeContext().getState(new ValueStateDescriptor<>("myState", Long.class));
}
#Override
public void processElement(Event event, Context ctx, Collector<String> out) throws Exception {
// update our state and timer
Long current = lastModifiedState.value();
if (current != null) {
ctx.timerService().deleteEventTimeTimer(current + TIMEOUT);
}
current = max(current, event.timestamp());
lastModifiedState.update(current);
ctx.timerService().registerEventTimeTimer(current + TIMEOUT);
}
#Override
public void onTimer(long timestamp, OnTimerContext ctx, Collector<String> out) throws Exception {
// emit alert
String deviceId = ctx.getCurrentKey();
out.collect(deviceId);
}
}
This assumes a main program that does something like this:
DataStream<String> result = stream
.assignTimestampsAndWatermarks(new MyBoundedOutOfOrdernessAssigner(...))
.keyBy(e -> e.deviceId)
.process(new TimeoutFunction());
As #Dominik said, this only emits alerts for keys that have been seen at least once. You could fix that by introducing a secondary source of events that creates an artificial event for every source that should exist, and union that stream with the primary source.
The pattern is very clear to me now. I've implemented the solution and it works like charm.
If anyone needs the code, then I'll be happy to share
I am working on AngularJS, WebApi. Have angular services to fetch data from database using Entity-Framework LINQ.
So, when I run my app, I want to see how much time my web api took to return response from server?
How can we do it?
There are several ways to accomplish this thing.
First way is to use ActinoFilter. For that refer this answer.
Second way is to use Middleware
Add new class file, here it's LoggingMiddleware
public class LoggingMiddleware
{
private readonly RequestDelegate _next;
LoggingDataAccess _loggingDataAccess; // your data access
readonly Stopwatch _stopwatch = new Stopwatch();
public LoggingMiddleware(RequestDelegate next, LoggingDataAccess loggingDataAccess)
{
_next = next;
_loggingDataAccess = loggingDataAccess;
}
public async Task Invoke(HttpContext context)
{
// start request time
_stopwatch.Start();
await _next.Invoke(context);
// end request time and get elapsed milliseconds
_stopwatch.Stop();
// save time to your table
var time= _stopwatch.ElapsedMilliseconds;
//reset stopwatch
_stopwatch.Reset();
}
}
Add your Middleware in Startup.cs (ASP.NET Core)
public void Configure(IApplicationBuilder app...)
{
app.UseMiddleware<LoggingMiddleware>();
}
Hope this helps!
I am trying to make my game play two different pieces of music one after another. I am using two separate clips because each one of them is associated to a different animation. In order to make the second music clip wait for the first one to finish I am using Timer.schedule(Task aTask, float delay). This seems to work fine. However, after the second music clip finishes I need to change the screen and dispose of the current screen, so I’m using Timer.schedule(Task aTask, float delay) again so that the change happens after the second music clip finishes. However, I am having problems with placing dispose() inside the Timer.Task as the console gives an error starting:
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: buffer not allocated with newUnsafeByteBuffer or already disposed …
My code looks like this:
aMusic.play();
Timer.schedule(new Task(){
#Override
public void run(){
anotherMusic.play();
}
},2.0f);
Timer.schedule(new Task(){
#Override
public void run(){
aGame.setScreen(new newScreen(aGame));
dispose();
}
},10.0f);
Is there another way to make the dispose() method wait other than using Timer (and while keeping the thread active as the audio needs to be playing)?
Thanks
ccm
You can use an OnCompleteListener for this:
music.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(Music music) {
}
});
This way you can wait until the first track is completed, play the second and dispose it... :)
Hope it helps...
I've developed a graph control in GDI+ and used a timer in it.. now i'm converting it to
WPF. but when i went on and search for a timer there is no timers in WPF... how can i resolve this problem?any alternative to use?
regards,
rangana.
You can use System.Threading.Timer without any problems I suppose.
Here is an example of a timer which executes every 1 sec:
using System.Threading;
...
TimerCallback timerCallBack = OnTimerCallback;
Timer timer = new Timer(timerCallBack, null, 0, 1000);
...
private void OnTimerCallback(object state)
{
...
}
If you want to update any UI related elements from the timer, you will have to use Dispatcher.BeginInvoke because the timer runs in it's own thread and the UI is owned by the main thread which starts the timer. Here is an example:
private void OnTimerCallback(object state)
{
Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
(ThreadStart) (() => Background = Brushes.Black));
}
The timer you are looking for is DispatcherTimer http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx
But, if you plan to use a timer to drive animations, there are better ways to do that in WPF (just Google WPF animation).