View Source MishkaInstaller.PluginState (Mishka Installer v0.0.4)

This module served as the first layer in the domain of plugin state management in earlier versions; however, following optimization using ETS, it is now regarded as the main structure in the second layer.

If a developer chooses to construct a custom plugin by using the use MishkaInstaller.Hook directive, then the developer actually implements this module as the first layer to register a plugin and the second layer as a supervisor. The scope of a plugin's state management is not restricted to the automatically specified duties performed by the MishkaInstaller; for instance, it provides developers with a temporary state and offers them the freedom to act in accordance with whatever method they choose.

each-plugin-should-have-these-parameters

Each plugin should have these parameters

  defstruct [:name, :event, priority: 1, status: :started, depend_type: :soft, depends: [], extra: [], parent_pid: nil]

module-communication-process-of-mishkainstaller-pluginstate

Module communication process of MishkaInstaller.PluginState

       +------------------------------------------------+
       |                                                |
       |                                                |
+------+  MishkaInstaller.PluginStateDynamicSupervisor  |
|      |                                                |
|      |                                                |
|      +--------------------------------------+----^----+
|                                             |    |
|                                             |    |
|                                             |    |
|      +------------------------+             |    |
|      |                        |             |    |
+------>  PluginStateRegistry   |             |    |
       |                        |             |    |
       +--------^---------------+             |    |
                |                             |    |
                |                             |    |
                |                             |    |
                |                             |    |
                |        +--------------------v----+-----+
                |        |                               |
                |        |  MishkaInstaller.PluginState  |
                +--------+                               |
                         +--------------------+--------^-+
                                              |        |
                                              |        |
                                              |        |
                                              |        |
          +----------------------------+      |        |
          |                            |      |        |
          | MishkaInstaller.PluginETS  <------+        |
          |                            |               |
          +----------------------------+               |
                                                       |
                                                       |
                                                       |
                                  +--------------------+-+
                                  |                      |
                    +-------------+ MishkaInstaller.Hook |
                    |             |                      |
                    |             +----------------------+
                    |
                    |
          +---------v----------------------+
          |                                |
          |     Behaviour References       |
          |                                |
          +--------------------------------+

Link to this section Summary

Types

This type can be used when you want to introduce an event name

This type can be used when you want to introduce an event owner extension

This type can be used when you want to introduce an ID of a plugin

This type can be used when you want to introduce an plugin name

This type can be used when you want to introduce the parameters of a plugin

This type can be used when you want to introduce an event

t()

This type can be used when you want to introduce an event

Functions

Delete a plugin or plugins based on a specific event from the state.

Terminate a PID from the supervisor directly.

It gets a plugin information from the state.

This function gets all information of plugins which are pushed on the state.

This function gets all information of plugins which are under a specific event.

This function helps you to create the state of a plugin. Please see plugin/0 type documents. This function does not wait for a response.

This function does the same thing as the push/1 function, except that it waits for a response.

You should in no way use this function in its direct form. The supervisor coverage needs to run before using this function since it will establish a state for your plugin and save its PID in the registry. Make use of the function named MishkaInstaller.PluginStateDynamicSupervisor.start_job/1.

Stop a plugin state.

Terminate all PIDs of the plugin state from the supervisor directly.

Link to this section Types

@type event_name() :: String.t()

This type can be used when you want to introduce an event name

@type extension() :: String.t()

This type can be used when you want to introduce an event owner extension

@type id() :: String.t()

This type can be used when you want to introduce an ID of a plugin

@type module_name() :: String.t()

This type can be used when you want to introduce an plugin name

@type params() :: map()

This type can be used when you want to introduce the parameters of a plugin

@type plugin() :: %MishkaInstaller.PluginState{
  depend_type: :soft | :hard,
  depends: [String.t()],
  event: event_name(),
  extension: module(),
  extra: [map()],
  name: module_name(),
  parent_pid: any(),
  priority: integer(),
  status: :started | :stopped | :restarted
}

This type can be used when you want to introduce an event

@type t() :: plugin()

This type can be used when you want to introduce an event

Link to this section Functions

Delete a plugin or plugins based on a specific event from the state.

examples

Examples

MishkaInstaller.PluginState.delete(module: "PluginTest")
# or
MishkaInstaller.PluginState.delete(event: "EventTest")

Terminate a PID from the supervisor directly.

examples

Examples

MishkaInstaller.PluginState.delete_child(module: "PluginTest")
@spec get([{:module, module_name()}]) :: plugin() | {:error, :get, :not_found}

It gets a plugin information from the state.

examples

Examples

MishkaInstaller.PluginState.get(module: "PluginTest")

This function gets all information of plugins which are pushed on the state.

examples

Examples

MishkaInstaller.PluginState.get_all()

This function gets all information of plugins which are under a specific event.

examples

Examples

MishkaInstaller.PluginState.get_all(event: "event_test")
@spec push(t()) :: :ok | {:error, :push, any()}

This function helps you to create the state of a plugin. Please see plugin/0 type documents. This function does not wait for a response.

examples

Examples

plugin =
  %MishkaInstaller.PluginState{
    name: "unnested_plugin_five",
    event: "nested_event_one",
    depend_type: :hard,
    depends: ["unnested_plugin_four"]
  }
MishkaInstaller.PluginState.push(plugin)
@spec push_call(t()) :: :ok | {:error, :push, any()}

This function does the same thing as the push/1 function, except that it waits for a response.

You should in no way use this function in its direct form. The supervisor coverage needs to run before using this function since it will establish a state for your plugin and save its PID in the registry. Make use of the function named MishkaInstaller.PluginStateDynamicSupervisor.start_job/1.

Stop a plugin state.

examples

Examples

MishkaInstaller.PluginState.stop(module: PluginTest)
# or
MishkaInstaller.PluginState.stop(event: "event_test")

Terminate all PIDs of the plugin state from the supervisor directly.

examples

Examples

MishkaInstaller.PluginState.terminate_all_pids()