Perl Is it possible to re-create the Net::Telnet connection if I have its memory location? - perl

Is it possible to re-create the Net::Telnet connection if I have its memory location ?
how can i turn Net::Telnet=GLOB(0x1b50ff0) string to a Net::Telnet object again ?
Thanks.

UPDATE
You can not re-use your object in 2 separate processes as it seems from your comments you are trying to do - one will NOT see the other's memory/address space. You can only do one of 3 things:
Re-create the object from scratch to be the duplicate of the other object in a different program, but only if the object's class supports serialization/de-serialization (usually done via saving object state using Data::Dumper, Storable or other methods). I don't know if Net::Telnet can be handled that way.
Just to be clear, your second program will obtain a COPY of the object once deserialized, which has nothing to do with the original object.
Allow the client to talk to the server and send Telnet commands, which the server passes to Net::telnet object and tells the client the result. Basically, the server acting as a telnet proxy for the client. The client should refer to server's Net::Telnet objects via their IDs, as mentioned in the registry explanation in my original answer.
Use shared memory to store Net::Telnet object if the client and server reside on the same physical server.
ORIGINAL ANSWER
You can try looking at Acme::Ref which un-stringifies a reference... I never used it so can't guarantee it works well or works with specifically Net::telnet.
I agree with the comment posted above that if you need to do this, you most likely are not applying a correct solution to your underlying problem - it would help if you provided more details of what you're trying to achieve high-level.
You should almost never have to deal with stringified reference as opposed to an object reference. If you're within the bounds of your own process, then you can pass the object reference around (or make it global if you really must). If you are using some sort of inter-process communication and an external process needs to refer to one of Net::Telnet objects in your program, you need to create a registry of Net::Telnet objects (could be just an array) and reference them by an index in the registry.

Related

Golang mgo store Session or Collection

When my server starts up, it will create a connection to a mongo database, grab that *mgo.Session and store it in a "server" struct for handlers defined on that struct to use to serve requests.
I see two ways to actually execute this.
1) Save the `*mgo.Session` in the struct.
The upside of this is that you can call Session.Copy in each handler before using the session to have connection isolation. The downside is that you need to call .DB("x").C("y") for a specific x and y for each handler. If you wanted to change this, you need to find each instance where you're using it and change it. That's less than ideal.
2) Store the `*mgo.Database` or even `*mgo.Collection` object on the server struct.
The upside is that you can configure it in one place and use it. The downside is that there appears to be no way to use Copy() on the thing for connection isolation.
How do you recommend storing the mongo session so that you can cleanly use the connection and provide isolation between requests?

Model parametrized API Call in Activity Diagram

I have an an activity diagram with two swimlanes (Client and Server). I want to model a request call from Client to Server.
Is it correct to use Signals Notation for Calls between systems? Are there alternatives?
The call is parametrized, Client wants to send something which was created before. How to model this?
Thankful for any hint! Here's my example:
My answer has to be improved, but here is a first step.
The norm/spec says: "A SendSignalAction is an InvocationAction that creates a Signal instance and transmits the instance to the object given on its target InputPin. A SendSignalAction must have argument InputPins corresponding, in order, to each of the (owned and inherited) Properties of the Signal being sent, with the same type, ordering and multiplicity as the corresponding attribute.
And a SendSignalAction has an association to a target objet which is an input pin.
So for your question about Request:item I would use input pin, one for the object from which the Signal is created and one to define the Target. (in the schema the target comes from an output pin but a data store may be use). Then after sending the request, the client is waiting the answer. The AcceptEvent is linked to a trigger (not shown on the schema) which a signal, the one created by the server. But you can not link SendRequest of Client to ReceiveRequest of Server because this is not how it runs.
For the server, you can do similar reasoning.
Concerning the parametrization of the call I would use InputPin to model the arguments of the Call i.e. the Object sent by the Call as shown below.
Signal and Call Notations are correct for me but I am not used to have the sending and receive action in the same diagram so will suggest two alternatives.
1) First remove them...
2) Separate Client and Server Modelling
Let me know what you think about that and what seems to be clear for you...
I also recognize the tool you used so please find my project at:
https://www.dropbox.com/s/s1mx46cb3linop0/Project1.zip?dl=0
As I see it, it should be modeled like this:
The server runs in an independent loop and starts with waiting for a request. There's a object flow between Create request and Query result set. This symbolizes data placed in a queue (or what ever is appropriate). The receipt of the result set would be done below in a similar way, I just left that out for brevity.
You can also draw an object for the query set
instead of the ActionPins.

Implementing Key-value server

I found a question and that is : to implement a key-value server
User should be able to connect to server and be able to run command SET a = b.
On running command GET a, it should print b.
First of all, I didn't really understand what the question is all about.
In its simplest form, a Key-Value server is nothing more but a server that holds keys in a dictionary structure and associates a value with said key.
If it helps, you can think of a key as a variable name in a programming language or as an environment variable in the bash shell.
A client to the Key-Value server would either tell the server what value the key has, or request the current value of the key from the server.
As Ramon mentioned in his comment, memcached.org is such example of a Key-Value server.
Of course, the server can be much more complex that what I described above. Keys could be more than just values (for instance, objects) and the server/client could have a lot more functionality than the basic set/get.
Note that the term Key-Value server is very broad and doesn't mean anything concrete by itself. NoSQL systems make use of key-value stores, for example, so you could technically call any NoSQL database system a Key-Value server.

Is there a way in scala to execute arbitrary code on a remote node around using RemoteActor?

For example, I have a trusted client and a server. The client wants to execute arbitrary code on the server. Can this be achieved using RemoteActor (serialize a function and send it across the network, deserialize it and execute it)?
Here's an example of using URLClassLoader with remote actors, to fetch the classes via http from the client and execute generic computations on the server.
You may also be interested in HotSwap technique applied to serializable Akka Actors.
Not currently. Serializing a function means storing its fields into a object output stream and deserializing it means reading the function object from an object input stream somewhere else. Deserialization presumes that the class of the object being read from the object input stream is known to the JVM. Remember - functions are just objects behind the scene.
In this case, the server does not know the actual concrete class of the function object you're serializing, just possibly that it implements the Function interface. To support such a functionality, you'd have to locate the class file of the function in question, send it to the server, and load it on the server using a custom classloader. Then, if the object has any kind of state, you could serialize the object on the client, send it over the network and deserialize it on the server. Only then can you run its methods. Assuming your function objects are stateless, which is usually the case, you could skip the serialization/deserialization step.
EDIT:
Remember, also, that functions may internally hold references to their calling environments. This means you might end up serializing the environment of a function object along with it, which can potentially be your entire program data..

MSMQ querying for a specific message

I have a questing regarding MSMQ...
I designed an async arhitecture like this:
CLient - > WCF Service (hosted in WinService) -> MSMQ
so basically the WCF service takes the requests, processes them, adds them to an INPUT queue and returns a GUID. The same WCF service (through a listener) takes first message from queue (does some stuff...) and then it puts it back into another queue (OUTPUT).
The problem is how can I retrieve the result from the OUTPUT queue when a client requests it... because MSMQ does not allow random access to it's messages and the only solution would be to iterate through all messages and push them back in until I find the exact one I need. I do not want to use DB for this OUTPUT queue, because of some limitations imposed by the client...
You can look in your Output-Queue for your message by using
var mq = new MessageQueue(outputQueueName);
mq.PeekById(yourId);
Receiving by Id:
mq.ReceiveById(yourId);
A queue is inherently a "first-in-first-out" kind of data structure, while what you want is a "random access" data structure. It's just not designed for what you're trying to achieve here, so there isn't any "clean" way of doing this. Even if there was a way, it would be a hack.
If you elaborate on the limitations imposed by the client perhaps there might be other alternatives. Why don't you want to use a DB? Can you use a local SQLite DB, perhaps, or even an in-memory one?
Edit: If you have a client dictating implementation details to their own detriment then there are really only three ways you can go:
Work around them. In this case, that could involve using a SQLite DB - it's just a file and the client probably wouldn't even think of it as a "database".
Probe deeper and find out just what the underlying issue is, ie. why don't they want to use a DB? What are their real concerns and underlying assumptions?
Accept a poor solution and explain to the client that this is due to their own restriction. This is never nice and never easy, so it's really a last resort.
You may could use CorrelationId and set it when you send the message. Then, to receive the same message you can pick the specific message with ReceiveByCorrelationId as follow:
message = queue.ReceiveByCorrelationId(correlationId);
Moreover, CorrelationId is a string with the following format:
Guid()\\Number