Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:55:38+00:00 2026-06-03T22:55:38+00:00

I have to process individual objects of type InternalMessage , convert each one into

  • 0

I have to process individual objects of type InternalMessage, convert each one into some number of ExternalMessage objects (there is a one-to-many relationship between InternalMessages and ExternalMessages), and put these ExternalMessage objects on a queue to be processed. I want to have two modes of inserting onto this queue – batched, where all of the ExternalMessage are inserted onto the queue atomically, and normal insertion, where the ExternalMessage objects are inserted onto the queue as they are created. Note that there are multiple threads producing messages for this queue.

My thought on solving this is having an Inserter object, which handles the insertion:

class Inserter {
public:
    void ProcessMessage(const ExternalMessage& externalMessage) = 0;
};

class SingleInserter {
public:
    SingleInserter(Queue* q) : m_q(q) { }
    void ProcessMessage(const ExternalMessage& externalMessage) {
        m_q->Insert(q);
    }
private:
    Queue* m_q;
};

class BatchInserter {
public:
    BatchInserter(Queue* q) : m_q(q) { }
    void ProcessMessage(const ExternalMessage& externalMessage) {
        m_cache.Insert(externalMessage);
    }
    ~BatchInserter() {
        m_q->BatchInsert(m_cache);
    }

private:
    Queue* m_q;
    List<ExternalMessages> m_cache;
};

And then passing the Inserter down the call stack as messages are created.

BatchInserter ins;

or

SingleInserter ins;

and then

HandleMessage(someInternalMessage, ins);

and HandleMessage will do:

void HandleMessage(const InternalMessage& msg, Inserter& ins) {
    //... do logic, eventually create a externalMsg (note - this could be further down
    //the call stack, in a loop, etc. Multiple external messages could be created each
    //call to HandleMessage)
    ins.ProcessMessage(externalMsg);
}

Is this design ideal? It’s nice that it allows for different insertion types, but is there some way to do this without having to pass an object down the call stack (say, via template specialization)? Secondly, is there an STL pattern that I should be conforming to in implementing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:55:39+00:00Added an answer on June 3, 2026 at 10:55 pm

    It looks ok to me. Only change I could think of is making HandleMessage a template. So you will have template <class T> HandleMessage(const InternalMessage& msg, T& inserter). With this you will not be forcing the user of this class to derive from the abstract base class Inserter and will avoid the little overhead caused by the dynamic dispatch due to virtual functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I have a process which iterates through a bunch of ActiveRecord models, does some
So I have a java class that takes individual commands and puts them into
I have an Int that i want to split into it's individual numbers which
I have a delimited list of IPs I'd like to process individually. The list
Here is what I have: process = subprocess.Popen([cmd.exe, /c appcfg.py, upload_data, --config_file=..\\bulkloader.yaml, --filename= +
I have a process which has a notify method which receives as a parameter
I have a process which gives me continuously output in Screen. I want to
I have a process I want to run in the background of a page.
I have a process intensive task that I would like to run in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.