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.










share|improve this question






















  • 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















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.










share|improve this question






















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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


















  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

WPF add header to Image with URL pettitions [duplicate]