Fire event when queue is almost full
up vote
0
down vote
favorite
I have a use-case where I am populating my blocking queue
with a lot of data.
Now, I want to fire an event(call a method) when this queue gets 90%(arbitrary value) full.
I want to achieve this so that I can perform an operation on the bulk data from the queue.
For this, I am thinking of extending one of the implementations of BlockingQueue
such as LinkedBlockingQueue
and overriding the put(...)
method and do something like:
...
@Override
public void put(E e) {
super.put(e);
if(this.percentageUsed() >= 90)
fireEvent(this);
}
...
And write my logic to deal with the BlockingQueue
object in the fireEvent
method.
This could very well be done using a scheduler to poll the size of the queue every n
seconds
, but if I had many of these queues in my application, it would create havoc to handle all the schedulers. Also, this approach would keep everything in a single class file and much cleaner code.
Please provide an expert insight into this approach.
java events data-structures event-listener blockingqueue
|
show 1 more comment
up vote
0
down vote
favorite
I have a use-case where I am populating my blocking queue
with a lot of data.
Now, I want to fire an event(call a method) when this queue gets 90%(arbitrary value) full.
I want to achieve this so that I can perform an operation on the bulk data from the queue.
For this, I am thinking of extending one of the implementations of BlockingQueue
such as LinkedBlockingQueue
and overriding the put(...)
method and do something like:
...
@Override
public void put(E e) {
super.put(e);
if(this.percentageUsed() >= 90)
fireEvent(this);
}
...
And write my logic to deal with the BlockingQueue
object in the fireEvent
method.
This could very well be done using a scheduler to poll the size of the queue every n
seconds
, but if I had many of these queues in my application, it would create havoc to handle all the schedulers. Also, this approach would keep everything in a single class file and much cleaner code.
Please provide an expert insight into this approach.
java events data-structures event-listener blockingqueue
What do you need exactly? yes, for what you want you need to override the method and provide your own implementation that calls previous implementations and adds something mor. This is called Observer and Proxy.
– Sarief
2 days ago
I need an event listener for when the queue inX%
filled.
– Aditya Gupta
yesterday
so create it. Do you have problems in how to design it? if so - please look at Observer and Proxy. If not, please explain.
– Sarief
yesterday
I have designed the structure but wanted a critical review on this approach. Whether it's a good idea to do so, etc.
– Aditya Gupta
yesterday
Can't say: I have no info on the model you're working with. You ask how good is a dress by the color of the needle. Not really going to work. You ask if there is a catch? well, any structure, like list, map or queue are normally self-expanding, meaning they will increase in size once they reach certain limit. I.e. you will never reach 90% load, unless you have 2^16 items. So you better decide on independand value of maximum size. Otherwise it boils down to bigger picture :)
– Sarief
yesterday
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a use-case where I am populating my blocking queue
with a lot of data.
Now, I want to fire an event(call a method) when this queue gets 90%(arbitrary value) full.
I want to achieve this so that I can perform an operation on the bulk data from the queue.
For this, I am thinking of extending one of the implementations of BlockingQueue
such as LinkedBlockingQueue
and overriding the put(...)
method and do something like:
...
@Override
public void put(E e) {
super.put(e);
if(this.percentageUsed() >= 90)
fireEvent(this);
}
...
And write my logic to deal with the BlockingQueue
object in the fireEvent
method.
This could very well be done using a scheduler to poll the size of the queue every n
seconds
, but if I had many of these queues in my application, it would create havoc to handle all the schedulers. Also, this approach would keep everything in a single class file and much cleaner code.
Please provide an expert insight into this approach.
java events data-structures event-listener blockingqueue
I have a use-case where I am populating my blocking queue
with a lot of data.
Now, I want to fire an event(call a method) when this queue gets 90%(arbitrary value) full.
I want to achieve this so that I can perform an operation on the bulk data from the queue.
For this, I am thinking of extending one of the implementations of BlockingQueue
such as LinkedBlockingQueue
and overriding the put(...)
method and do something like:
...
@Override
public void put(E e) {
super.put(e);
if(this.percentageUsed() >= 90)
fireEvent(this);
}
...
And write my logic to deal with the BlockingQueue
object in the fireEvent
method.
This could very well be done using a scheduler to poll the size of the queue every n
seconds
, but if I had many of these queues in my application, it would create havoc to handle all the schedulers. Also, this approach would keep everything in a single class file and much cleaner code.
Please provide an expert insight into this approach.
java events data-structures event-listener blockingqueue
java events data-structures event-listener blockingqueue
asked 2 days ago
Aditya Gupta
412514
412514
What do you need exactly? yes, for what you want you need to override the method and provide your own implementation that calls previous implementations and adds something mor. This is called Observer and Proxy.
– Sarief
2 days ago
I need an event listener for when the queue inX%
filled.
– Aditya Gupta
yesterday
so create it. Do you have problems in how to design it? if so - please look at Observer and Proxy. If not, please explain.
– Sarief
yesterday
I have designed the structure but wanted a critical review on this approach. Whether it's a good idea to do so, etc.
– Aditya Gupta
yesterday
Can't say: I have no info on the model you're working with. You ask how good is a dress by the color of the needle. Not really going to work. You ask if there is a catch? well, any structure, like list, map or queue are normally self-expanding, meaning they will increase in size once they reach certain limit. I.e. you will never reach 90% load, unless you have 2^16 items. So you better decide on independand value of maximum size. Otherwise it boils down to bigger picture :)
– Sarief
yesterday
|
show 1 more comment
What do you need exactly? yes, for what you want you need to override the method and provide your own implementation that calls previous implementations and adds something mor. This is called Observer and Proxy.
– Sarief
2 days ago
I need an event listener for when the queue inX%
filled.
– Aditya Gupta
yesterday
so create it. Do you have problems in how to design it? if so - please look at Observer and Proxy. If not, please explain.
– Sarief
yesterday
I have designed the structure but wanted a critical review on this approach. Whether it's a good idea to do so, etc.
– Aditya Gupta
yesterday
Can't say: I have no info on the model you're working with. You ask how good is a dress by the color of the needle. Not really going to work. You ask if there is a catch? well, any structure, like list, map or queue are normally self-expanding, meaning they will increase in size once they reach certain limit. I.e. you will never reach 90% load, unless you have 2^16 items. So you better decide on independand value of maximum size. Otherwise it boils down to bigger picture :)
– Sarief
yesterday
What do you need exactly? yes, for what you want you need to override the method and provide your own implementation that calls previous implementations and adds something mor. This is called Observer and Proxy.
– Sarief
2 days ago
What do you need exactly? yes, for what you want you need to override the method and provide your own implementation that calls previous implementations and adds something mor. This is called Observer and Proxy.
– Sarief
2 days ago
I need an event listener for when the queue in
X%
filled.– Aditya Gupta
yesterday
I need an event listener for when the queue in
X%
filled.– Aditya Gupta
yesterday
so create it. Do you have problems in how to design it? if so - please look at Observer and Proxy. If not, please explain.
– Sarief
yesterday
so create it. Do you have problems in how to design it? if so - please look at Observer and Proxy. If not, please explain.
– Sarief
yesterday
I have designed the structure but wanted a critical review on this approach. Whether it's a good idea to do so, etc.
– Aditya Gupta
yesterday
I have designed the structure but wanted a critical review on this approach. Whether it's a good idea to do so, etc.
– Aditya Gupta
yesterday
Can't say: I have no info on the model you're working with. You ask how good is a dress by the color of the needle. Not really going to work. You ask if there is a catch? well, any structure, like list, map or queue are normally self-expanding, meaning they will increase in size once they reach certain limit. I.e. you will never reach 90% load, unless you have 2^16 items. So you better decide on independand value of maximum size. Otherwise it boils down to bigger picture :)
– Sarief
yesterday
Can't say: I have no info on the model you're working with. You ask how good is a dress by the color of the needle. Not really going to work. You ask if there is a catch? well, any structure, like list, map or queue are normally self-expanding, meaning they will increase in size once they reach certain limit. I.e. you will never reach 90% load, unless you have 2^16 items. So you better decide on independand value of maximum size. Otherwise it boils down to bigger picture :)
– Sarief
yesterday
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373172%2ffire-event-when-queue-is-almost-full%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you need exactly? yes, for what you want you need to override the method and provide your own implementation that calls previous implementations and adds something mor. This is called Observer and Proxy.
– Sarief
2 days ago
I need an event listener for when the queue in
X%
filled.– Aditya Gupta
yesterday
so create it. Do you have problems in how to design it? if so - please look at Observer and Proxy. If not, please explain.
– Sarief
yesterday
I have designed the structure but wanted a critical review on this approach. Whether it's a good idea to do so, etc.
– Aditya Gupta
yesterday
Can't say: I have no info on the model you're working with. You ask how good is a dress by the color of the needle. Not really going to work. You ask if there is a catch? well, any structure, like list, map or queue are normally self-expanding, meaning they will increase in size once they reach certain limit. I.e. you will never reach 90% load, unless you have 2^16 items. So you better decide on independand value of maximum size. Otherwise it boils down to bigger picture :)
– Sarief
yesterday