Quantcast

Question about using ETS, PUT/GET

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about using ETS, PUT/GET

flowerstars
This post has NOT been accepted by the mailing list yet.
Hi everyone,

I am working on developing modules on ejabberd. I tried to use ETS in start/2. The codes are following:

  ets:new(table_name, [named_table, public, bag]),
  ets:insert(table_name, {num, 999}),

I use "ets:lookup(table_name, num)," in another function within the same file to read the value "999".

The issue is I cannot start ejabberd, according to the log, when the second time this module starts, ejabberd tells there is an argument error.

Actually, I just want to share some variables. I used to use PUT/2 and GET/1, I use "put(key, Value)" in start/2, and use "get(key)" in another function within one file. However, what I got is "undefined". Are they in the same process?

Any help is appreciated!!

Thanks a lot!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about using ETS, PUT/GET

Dmitry Kolesnikov
Hello,

> The issue is I cannot start ejabberd, according to the log, when the second
> time this module starts, ejabberd tells there is an argument error.


this is due to your named ets table. When you stat this module second time the table_name is exists and ets throws an error. You have to re-shake you app in the way that only one copy of ets is created.

- Dmitry

On Feb 15, 2012, at 11:16 PM, flowerstars wrote:

> Hi everyone,
>
> I am working on developing modules on ejabberd. I tried to use ETS in
> start/2. The codes are following:
>
>  ets:new(table_name, [named_table, public, bag]),
>  ets:insert(table_name, {num, 999}),
>
> I use "ets:lookup(table_name, num)," in another function within the same
> file to read the value "999".
>
> The issue is I cannot start ejabberd, according to the log, when the second
> time this module starts, ejabberd tells there is an argument error.
>
> Actually, I just want to share some variables. I used to use PUT/2 and
> GET/1, I use "put(key, Value)" in start/2, and use "get(key)" in another
> function within one file. However, what I got is "undefined". Are they in
> the same process?
>
> Any help is appreciated!!
>
> Thanks a lot!
>
>
> --
> View this message in context: http://erlang.2086793.n4.nabble.com/Question-about-using-ETS-PUT-GET-tp4392011p4392011.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about using ETS, PUT/GET

steven join
This post has NOT been accepted by the mailing list yet.
In reply to this post by flowerstars
I got the same situation..........
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about using ETS, PUT/GET

Alexey Eremikihin
In reply to this post by Dmitry Kolesnikov
Small hint
Ejabberd starts new instance of module for each domain specified in config.
So modules are domain specific.

You need to decide do you need one table for all domains, or each domain
has its own table.

16.02.2012 01:22, Dmitry Kolesnikov ?????:

> Hello,
>
>> The issue is I cannot start ejabberd, according to the log, when the second
>> time this module starts, ejabberd tells there is an argument error.
>
> this is due to your named ets table. When you stat this module second time the table_name is exists and ets throws an error. You have to re-shake you app in the way that only one copy of ets is created.
>
> - Dmitry
>
> On Feb 15, 2012, at 11:16 PM, flowerstars wrote:
>
>> Hi everyone,
>>
>> I am working on developing modules on ejabberd. I tried to use ETS in
>> start/2. The codes are following:
>>
>>   ets:new(table_name, [named_table, public, bag]),
>>   ets:insert(table_name, {num, 999}),
>>
>> I use "ets:lookup(table_name, num)," in another function within the same
>> file to read the value "999".
>>
>> The issue is I cannot start ejabberd, according to the log, when the second
>> time this module starts, ejabberd tells there is an argument error.
>>
>> Actually, I just want to share some variables. I used to use PUT/2 and
>> GET/1, I use "put(key, Value)" in start/2, and use "get(key)" in another
>> function within one file. However, what I got is "undefined". Are they in
>> the same process?
>>
>> Any help is appreciated!!
>>
>> Thanks a lot!
>>
>>
>> --
>> View this message in context: http://erlang.2086793.n4.nabble.com/Question-about-using-ETS-PUT-GET-tp4392011p4392011.html
>> Sent from the Erlang Questions mailing list archive at Nabble.com.
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions
>
>



Loading...