You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PluginState.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2012-present the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j;
  17. /**
  18. * The state of a plugin.
  19. * <p>
  20. * Lifecycle of a plugin:
  21. * <pre>
  22. * CREATED -> RESOLVED -> STARTED -> STOPPED
  23. * CREATED -> DISABLED
  24. * CREATED -> FAILED
  25. *
  26. * @author Decebal Suiu
  27. */
  28. public enum PluginState {
  29. /**
  30. * The runtime knows the plugin is there. It knows about the plugin path, the plugin descriptor.
  31. */
  32. CREATED("CREATED"),
  33. /**
  34. * The plugin cannot be used.
  35. */
  36. DISABLED("DISABLED"),
  37. /**
  38. * The plugin is created. All the dependencies are created and resolved.
  39. * The plugin is ready to be started.
  40. */
  41. RESOLVED("RESOLVED"),
  42. /**
  43. * The {@link Plugin#start()} has executed. A started plugin may contribute extensions.
  44. */
  45. STARTED("STARTED"),
  46. /**
  47. * The {@link Plugin#stop()} has executed.
  48. */
  49. STOPPED("STOPPED"),
  50. /**
  51. * Plugin failed to start.
  52. */
  53. FAILED("FAILED");
  54. private final String status;
  55. PluginState(String status) {
  56. this.status = status;
  57. }
  58. public boolean equals(String status) {
  59. return (this.status.equalsIgnoreCase(status));
  60. }
  61. @Override
  62. public String toString() {
  63. return status;
  64. }
  65. /**
  66. * Parse a string to a {@link PluginState}.
  67. *
  68. * @param string the string to parse
  69. * @return the {@link PluginState} or null if the string is not a valid state
  70. */
  71. public static PluginState parse(String string) {
  72. for (PluginState status : values()) {
  73. if (status.equals(string)) {
  74. return status;
  75. }
  76. }
  77. return null;
  78. }
  79. }