Flink-Siddhi control event failing to start - flink-streaming

While trying to configure and implement flink- siddhi(https://clojars.org/com.github.haoch/flink-siddhi_2.11/versions/0.2.2-SNAPSHOT) control stream for rule ingestion , I am getting below error: Abstract method error as below:
Exception in thread "main" java.lang.AbstractMethodError
at org.apache.flink.streaming.api.graph.StreamGraphGenerator.lambda$generate$0(StreamGraphGenerator.java:305)
at java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)
at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1361)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
at java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:449)
at org.apache.flink.streaming.api.graph.StreamGraphGenerator.generate(StreamGraphGenerator.java:305)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.getStreamGraph(StreamExecutionEnvironment.java:2010)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.getStreamGraph(StreamExecutionEnvironment.java:1995)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.execute(StreamExecutionEnvironment.java:1834)
at flinksidhi.app.s3.SiddhiTestApp.start(SiddhiTestApp.java:104)
at flinksidhi.S3SidhiApp.main(S3SidhiApp.java:8)
Code for Control event:
Properties properties = new Properties();
properties.setProperty("bootstrap.servers", kafkaAddress);
properties.setProperty("zookeeper.connect",zkAddress );
properties.setProperty("group.id","test_rule");
DataStream<? extends ControlEvent> ruleControlStream = env.addSource(new FlinkKafkaConsumer("S3_RULE_STREAM_INPUT",
new ControlEventSchema(), properties));
Any help on this will be much needed ...
Regards
Dipanjan

Related

WebView2 | CoreWebView2DownloadStartingEvent Error

I need help when i`m starting the webbrowser then i getting this error, i dont know why is it null
CoreWebView2 WebView2;
public TabViewItem CurrentTab;
public TabContent()
{
this.InitializeComponent();
Browser.CoreWebView2.DownloadStarting += DownloadStarting_Event;
}
private void DownloadStarting_Event(CoreWebView2 sender, CoreWebView2DownloadStartingEventArgs args)
{
Debug.WriteLine("This is a test");
}
Exception thrown: 'System.ArgumentException' in System.Private.CoreLib.dll
An exception of type 'System.ArgumentException' occurred in System.Private.CoreLib.dll but was not handled in user code
Delegate to an instance method cannot have null 'this'.
Its not totally clear from the code you have shared, but it doesn't look like you are waiting for the WebView2 element to initialize its CoreWebView2 property before using the CoreWebView2 property. This is described in detail in the WebView2 reference documentation.
In brief, you must await a successful call to WebView2.EnsureCoreWebView2Async() or wait until the WebView2.CoreWebView2InitializationCompleted event is raised successfully before using the WebView2.CoreWebView2 property.

kotlin.KotlinNullPointerException while accessing Data from local Room Database?

I am new into Kotlin and trying to learn, how to fetch Data with retrofit and store this data into a Room DB. But as soon as i start the Activity where this process takes place i get a NullPointerException.
EDIT: As far as i could find out now, my "database" in the RoomViewmodel class is still NULL when i want to access it, even though i have an override oncreate function, where it is created
Here is also a link to the GitHub repository from the mini-project I'm working on: https://github.com/Engin92/Dog_Breeds/tree/RoomDatabase
here is my complete errorlist:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dogbreeds, PID: 14803
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dogbreeds/com.example.Breedlist.activity.DetailedViewActivity}: kotlin.KotlinNullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: kotlin.KotlinNullPointerException
at com.example.Breedlist.activity.DetailedViewActivityRepository.getBreeds(DetailedViewActivityRepository.kt:23)
at com.example.Breedlist.activity.DetailedViewActivityViewModel.getAllBreedList(DetailedViewActivityViewModel.kt:23)
at com.example.Breedlist.activity.DetailedViewActivity.onCreate(DetailedViewActivity.kt:42)
at android.app.Activity.performCreate(Activity.java:8086)
at android.app.Activity.performCreate(Activity.java:8074)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3755)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:213) 
at android.app.ActivityThread.main(ActivityThread.java:8178) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 
The important part of DetailedViewActivity
class DetailedViewActivity : AppCompatActivity() {
lateinit var breedRecyclerView: RecyclerView
lateinit var detailedViewActivityViewModel: DetailedViewActivityViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detailed_view)
breedRecyclerView = findViewById(R.id.breedRecyclerView)
detailedViewActivityViewModel = ViewModelProviders.of(this).get(
DetailedViewActivityViewModel::class.java)
if(isOnline(this))
{
detailedViewActivityViewModel.getBreedsFromAPIAndStore()
}
else
{
Toast.makeText(this,"No internet connection. Showing cached list!",Toast.LENGTH_LONG).show()
}
detailedViewActivityViewModel.getAllBreedList().observe(this, Observer<List<CurrentBreedResponseItem>> { breedList ->
Log.e(MainActivity::class.java.simpleName,breedList.toString())
setUpBreedRecyclerView(breedList!!)
})
} ....
the class RoomViewModel, where i build the DB (where i Think the error is, the var database is still NULL, after trying to access (write/read) it)
class RoomViewModel : Application() {
companion object {
var database: BreedDatabase? = null
}
override fun onCreate() {
super.onCreate()
database = Room.databaseBuilder(applicationContext, BreedDatabase::class.java, "breed_db").fallbackToDestructiveMigration().build()
}
}
getBreeds function in DetailedViewActivityRepository:
fun getBreeds() : LiveData<List<CurrentBreedResponseItem>>
{
return RoomViewModel.database!!.currentBreedDao().getAllBreeds()
}
getAllBreedList function in DetailedViewActivityViewModel
fun getAllBreedList(): LiveData<List<CurrentBreedResponseItem>>
{
return detailedViewActivityRepository.getBreeds()
}
There are two problem in your code. The first one is very clear you are trying to access a null object and you are getting NullPointerException. So be careful when you use !! operator.
The reason you are getting it is, inside your RoomViewModel your database instance is null.
class RoomViewModel : Application() {
companion object {
var database: BreedDatabase? = null
}
override fun onCreate() {
super.onCreate()
database = Room.databaseBuilder(applicationContext, BreedDatabase::class.java, "breed_db")
.fallbackToDestructiveMigration().build()
}
}
You may think you are initializing the database instance in onCreate() but the onCreate() is not getting called. The reason is to make the application class work you need to add it to your AndroidManifest.xml file.
Solution:
Add this RoomViewModel class to your AndroidManifest.xml file like this.
<application
android:name=".view.RoomViewModel"
android:allowBackup="true"
We do it as application tag's name attribute as you can see above.
This will fix your null pointer exception. But your program will again crash, because you are using Kotlin and do make room work with kotlin this thing needs to be added in your app level build.gradle file.
kapt "android.arch.persistence.room:compiler:1.1.1"
After adding it to your app level build.gradle inside dependencies block. Sync your project and run it should work.
If you want to learn more about Room Database in Android, you can check this Room Database Tutorial.
Hope this will help you.

Reload a Property from a Camel Route without stopping it

I'm trying to figure out a way to update dynamically a property (from a PropertyComponent) without stopping the Camel Route:
Here's an example of it:
#Override
public void configure() throws Exception {
CamelContext ctx = super.getContext();
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("/tmp/apache-deltaspike.properties");
ctx.addComponent("properties", pc);
// Logs Hello World every 2000 milliseconds
from("timer://myEapTimer?fixedRate=true&period=2000")
.log(LoggingLevel.INFO, "com.sample.route", "{{customProperty}}")
.to("log:HelloWorldLog?level=INFO");
}
The external Property file contains the message to be printed every time the Timer fires. I'd need to find a way to let the Route reload the Property file without stopping it.
BTW I'm using Apache Camel 2.17.0.
Thanks
That is not possible, the {{xxx}} is resolved only once when the route is starting up.
You can use a Java bean where you can load the properties file yourself and get the value and do the logging there.
Or you can call the Java bean with bean parameter binding and have the properties value injected. But you then also need to configure the properties component to not use caching etc.

Cross Thread Exception with Throttle in Reactive Extensions

I am using Reactive Extensions to verification of a textbox input.
I am trying to use the .Throttle(TimeSpan.FromMilliseconds(500)).
But when I add the .Throttle() method a cross thread exception is thrown when accessing a UI object in the .Subscribe() method.
It works 100% without the Throttle, why is it breaking?
My code:
var textChangedEvent = Observable.FromEvent<TextChangedEventArgs>(usernameTextbox, "TextChanged")
.Throttle(TimeSpan.FromMilliseconds(500))
textChangedEvent.Subscribe(changed =>
{
TextBox oUsernameTextBox = changed.Sender as TextBox;
//Accessing oUsernameTextBox throws Cross Thread Exception
});
Thanks
-Oliver
By default Throttle uses the ThreadpoolScheduler so events will not arrive on the UI Thread. Since you need the events on the UI thread use:-
var textChangedEvent = Observable.FromEvent<TextChangedEventArgs>(usernameTextbox, "TextChanged")
.Throttle(TimeSpan.FromMilliseconds(500), Scheduler.Dispatcher);
This will put the events back on the UI Thread.
I had to tweak the code a bit to make it work in a LightSwitch (SilverLight 4) application with Rx v1.0.10621 due to some interface changes in Rx since when this question had been asked.
Need to install Rx and to reference System.Reactive and System.Reactive.Windows.Threading assemblies (for LightSwitch this reference go in the Client project).
Then use this code to throttle a the TextChange event on the text box:
(Note: For lightswitch this code goes in the ControlAvailable handler)
var textChangedEvent = Observable
.FromEventPattern<TextChangedEventArgs>(e.Control, "TextChanged")
.Throttle(TimeSpan.FromMilliseconds(500))
.ObserveOnDispatcher();
textChangedEvent.Subscribe(changed =>
{
var tb = changed.Sender as TextBox;
if (tb.Text.Length >= 3) // don't search for keywords shorter than 3 chars
{
// search
}
});

Throw new Exception and Application_UnhandledException

My Scenario:
I'm using a Silverlight MVVM pattern. All my view models inherit from a BaseViewModel class that maintains some basic values and behaviours.
One of these behaviours determines if the user is authorised to use particular functionality and returns a boolean.
If the function is not located, I want to throw a new exception and catch this in the App.xaml Application_UnhandledException method, and raise my own exception event, something like this:
protected bool IsFunctionEnabled(string FunctionName)
{
//fetch the function / role
if (_FunctionRoles().ContainsValue(FunctionName))
{
KeyValuePair<int, string> kvp = _FunctionRoles().GetEntryByStringValue(FunctionName);
//determine if the user has been assigned to this role
return (_UserRoles().ContainsKey(kvp.Key));
}
//throw an exception when the function name is not located.
throw new Exception(string.Format(Constants.UNHANDLED_EXCEPTION, "security role assignment: '" + FunctionName + "' not located."));
}
I then want this automatically picked up in App.XAML:
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
// throw this message to the main application exception event handler
ApplicationEvents.OnExceptionOccurred(this,
new ExceptionEventArgs(e.ExceptionObject,
null,
ExceptionImportance.Critical));
}
My Problem
When the exception is thrown, it is not getting bubbled up the stack. When debugging the exception is hit over and over again, no other code is getting run.
What am I doing wrong here?
Thanks,
Mark
I think this is occurring because the exception is getting thrown outside of the UI thread, so there is no other code "waiting to run". Triggering an event here means writing a lot more code, but does allow the UI thread to subscribe to this and render a message in the UI properly.

Resources