Erlang otp app file




















We have the app file and a general idea of how applications work. Two simple callbacks. Opening ppool. We can then make sure the tests are still valid.

We can finally recompile the code and run all the tests to make sure everything still works we'll see how that eunit thing works later on, don't worry :. The tests take a while to run due to timer:sleep X being used to synchronise everything in a few places, but it should tell you everything works, as shown above. Good news, our app is healthy. The magic command here is application:start ppool. This tells the application controller to launch our ppool application.

What a surprise, ppool is running. As mentioned earlier, we can see that all applications depend on kernel and stdlib , which are both running. If we want to close the pool:. And it is done. Note: You'll sometimes see people do something like MyApp:start While this works for testing purposes, it's ruining a lot of the advantages of actually having an application: it's no longer part of the VM's supervision tree, can not access its environment variables, will not check dependencies before being started, etc.

Look at this! What's that thing about our app being temporary? We write Erlang and OTP stuff because it's supposed to run forever, not just for a while! How dare the VM say this? The secret is that we can give different arguments to application:start.

Depending on the arguments, the VM will react differently to termination of one of its applications. In some cases, the VM will be a loving beast ready to die for its children. In other cases, it's rather a cold heartless and pragmatic machine willing to tolerate many of its children dying for the survival of its species. You can see something new in the supervision strategies when it comes to applications. No longer will the VM try to save you. At this point, something has had to go very, very wrong for it to go up the whole supervision tree of one of its vital applications, enough to crash it.

When this does happen, the VM has lost all hope in your program. Given the definition of insanity is to do the same thing all over again while expecting different outcomes each time, the VM prefers to die sanely and just give up.

Of course the real reason has to do with something being broken that needs to be fixed, but you catch my drift. Take note that all applications can be terminated by calling application:stop AppName without affecting others as if a crash had occurred. What happens when we want to wrap flat modules in an application but we have no process to start and thus no need for an application callback module?

This is called a library application. If you want an example of one, the Erlang stdlib standard library application is one of these. Viewed times. I've tried the following sequence of commands to pick up all my new changes, but it doesn't seem to work: Compile src files Is there an easier way of picking up my changes? Chris Snow Chris Snow Have a look at mochiweb reloader.

Once started, process detects recompiled files and reloads it automatically. It's recommended for development stage only. Usually I'm only making changes to one or two modules at a time and reloading.

For this simply doing c module is good enough. If your code is structured as an OTP application then running make:all is very convenient you need an Emakefile, but a basic one is 1 or 2 lines erlang. Add a comment. Sets the value of configuration parameter Par for Application. This is also true for application reloads. Starts Application. It ensures that any included applications are loaded, but does not start them.

That is assumed to be taken care of in the code for Application. The application controller checks the value of the application specification key applications , to ensure that all applications needed to be started before this application are running.

Note this function makes no attempt to start any of the applications listed in applications , not even optional ones. Once validated, the application controller then creates an application master for the application.

The application master becomes the group leader of all the processes in the application. Used for example to find itself from any process, or, reciprocally, to kill them all when it terminates. Argument Type specifies the type of the application. If omitted, it defaults to temporary. Regardless of the type of the application, no other applications are affected.

Notice also that the transient type is of little practical use, because when a supervision tree terminates, the reason is set to shutdown , not normal. This function is intended to be called by a process belonging to an application, when the application is started, to determine the start type, which is StartType or local.

If the process executing the call does not belong to any application, the function returns undefined. Stops Application. This means that the entire supervision tree, including included applications, is terminated in reversed start order. Module is the callback module as defined by the application specification key mod.

Last, the application master terminates. Notice that all processes with the application master as group leader, that is, processes spawned from a process belonging to the application, are also terminated.

Takes over the distributed application Application , which executes at another node Node. Module and StartArgs are retrieved from the loaded application specification.

Thus, two instances of the application run simultaneously during the takeover, so that data can be transferred from the old to the new instance. If this is not an acceptable behavior, parts of the old instance can be shut down when the new instance is started. However, the application cannot be stopped entirely, at least the top supervisor must remain alive. Unloads the application specification for Application from the application controller. It also unloads the application specifications for any included applications.

Notice that the function does not purge the Erlang object code. Code loading is done the usual way. It checks the value of the applications key, to ensure that all applications that are to be started before this application are running.

The application controller then creates an application master for the application. The application master becomes the group leader of all the processes in the application. Used for example to find itself from any process, or, reciprocally, to kill them all when it terminates.

The application master stops the application by telling the top supervisor to shut down. The top supervisor tells all its child processes to shut down, and so on; the entire tree is terminated in reversed start order. An application can be configured using configuration parameters. Par is to be an atom. Val is any term. The values in the.

This is a file that contains configuration parameters for relevant applications:. The system configuration is to be called Name. For details, see the config 4 manual page in Kernel.



0コメント

  • 1000 / 1000