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 6153921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:28+00:00 2026-05-23T20:10:28+00:00

I want to extend gen_server (create a gen_server_extra ) with some additional functionality. The

  • 0

I want to extend gen_server (create a gen_server_extra) with some additional functionality. The requirements are:

  1. The gen_server_extra processes should behave like a regular gen_server‘s. E.g, they should accept calls via gen_server:call, integrate with SASL, fit OTC supervision tree, etc.
  2. gen_server_extra processes should have an additional functionality, provided by gen_server_extra. That basically means some of the messages will be handled by gen_server_extra code, without passing them to the callback module. The rest of the messages are passed to callback module as is.
  3. gen_server_extra functionality requires its own state which should be hidden from the callback module.

What is the simplest approach to do that?

  • 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-05-23T20:10:28+00:00Added an answer on May 23, 2026 at 8:10 pm

    The best, most modular approach would be to implement a new behavior in a module (e.g. gen_ext_server) and wrap the gen_server behavior from there.

    First, make sure your behavior is identical to gen_server:

    -module(gen_ext_server).
    -behavior(gen_server).
    
    % Exports...
    
    behaviour_info(Type) -> gen_server:behaviour_info(Type).
    

    Implement all callbacks needed for gen_server, keep the name of the callback module that implements your behavior in your state:

    init([Mod|ExtraArgs]) ->
        % ...
        ModState = Mod:init(ExtraArgs),
        #state{mod = Mod, mod_state = ModState, internal = [...]}
    

    Then, in each gen_server callback, implement your behavior and then call the callback module if needed:

    handle_call(internal, _From, State) ->
        % Do internal stuff...
        {reply, ok, State};
    handle_call(Normal, From, State = #state{mod = Mod, mod_state = ModState}) ->
        case Mod:handle_call(Normal, From, ModState) of
            {reply, Reply, NewState} ->
                {reply, Reply, #state{mod_state = NewState};
            ... ->
                ...
        end.
    

    Implement similar functionality for handle_cast/2, handle_info/2, terminate/1 etc.

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

Sidebar

Related Questions

I want to extend an open/save dialog with a drop-box which should look like
I want to extend a large C project with some new functionality, but I
I want to extend Zend_Db_Table_Row_Abstract to have some additional fields besides those from table.
I want to extend a WPF application with database functionality. Which database engine would
Let's say you have some 3rd-party library class that you want to extend, simply
I want to extend the System.Web.UI.Page-class with some extra stuff. In the ctor I
Me again. The sliding in works like a charm. But I want to extend
I want to extend the WebFormViewEngine so that I can perform some post-processing -
I want to extend some JQuery code to replace an image once I click
I want to extend the functionality of the ImageButton class, in a new class

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.