Vous pouvez créer un bundle de programme d'écoute de mise à l'échelle personnalisé
en utilisant WebSphere Application Server Developer Tools for Eclipse. Un programme d'écoute
de mise à l'échelle personnalisé est averti de toute action de mise à l'échelle en attente. Le programme d'écoute peut alors autoriser ou refuser l'action de mise à l'échelle. Il peut également décider de gérer l'action, fournissant ainsi une personnalisation complète
du comportement de mise à l'échelle.
Pourquoi et quand exécuter cette tâche
Vous devez implémenter l'interface de programme d'écoute et enregistrer la classe d'implémentation dans le registre de services. Votre programme d'écoute de mise à l'échelle peut autoriser ou refuser et gérer des actions de mise à l'échelle.
La documentation d'API Java pour chaque interface SPI
Liberty est disponible dans un fichier comprimé distinct dans l'un des sous-répertoires de documentation d'API du répertoire
${wlp.install.dir}/dev.
Procédure
- Cliquez sur
,
puis développez OSGi.
- Clique sur OSGi Bundle Project et sur
Next. La fenêtre New OSGi Bundle Project
s'affiche.
- Entrez ScalingSPISampleBundle comme nom du projet. Dans
la liste Target runtime, sélectionnez WebSphere
Application Server Liberty. S'il n'existe aucun environnement d'exécution, cliquez sur New Runtime
afin de créer une exécution WebSphere Application Server Liberty.
- Désélectionnez le bouton d'option Add bundle to application.
- Cliquez sur Next deux fois et accédez à
la page OSGi
Bundle.
- Dans la page OSGi Bundle, sélectionnez
Generate
an activator, a Java class that controls the life cycle of the bundle. Conservez la valeur scalingspisamplebundle.Activator
pour Activator name et cliquez sur
Finish.
- Cliquez sur
,
puis développez OSGi.
- Cliquez sur Liberty Feature Project,
puis sur Next. La fenêtre Liberty
Feature
Project s'affiche.
- Indiquez ScalingSPISampleFeature comme nom du projet.
- Dans la liste Target runtime, sélectionnez WebSphere
Application Server Liberty et cliquez sur Next. La page OSGi Bundles Selection s'affiche.
- Dans la page OSGi Bundles Selection,
sélectionnez ScalingSPISampleBundle
1.0.0 pour Contained Bundles et cliquez sur Finish.
- Cliquez sur et sélectionnez
WebSphere Application Server Liberty with SPI.
- Cliquez sur Apply et sur
OK.
- Développez
et ouvrez le fichier MANIFEST.MF à l'aide
de l'éditeur de manifeste de plug-in.
- Sélectionnez l'onglet Dependencies et ajoutez les packages
com.ibm.wsspi.scaling.action.consumer et com.ibm.wsspi.scaling.action.controller
au panneau Imported Packages. Vous devrez peut-être appuyer sur les touches
Ctrl+S pour sauvegarder les modifications.
- Dans le projet ScalingSPISampleBundle, ajoutez une classe d'implémentation appelée ScalingSPISamplePlugin. Cette nouvelle classe implémente l'interface com.ibm.wsspi.scaling.action.consumer.ScalingActionPlugin.
package scalingspisamplebundle;
import com.ibm.wsspi.scaling.action.consumer.ScalingActionPlugin;
import com.ibm.wsspi.scaling.action.controller.ScalingActionContext;
import com.ibm.wsspi.scaling.action.controller.ScalingActionContext.ActionType;
import com.ibm.wsspi.scaling.action.controller.ScalingActionContext.ActionDecision;;
/**
* This a sample Liberty scaling SPI plugin that acts as a template for developing a custom
* SPI plugin. In this plugin, no actual work is done and the return value to the Liberty Scaling
* controller is always DEFAULT_ACTION.
*
*/
public class ScalingSPISamplePlugin implements ScalingActionPlugin {
/** {@inheritDoc} */
@Override
public ActionDecision actionRequired(ScalingActionContext action) {
ActionDecision returnType = ActionDecision.DEFAULT_ACTION;
if (action.getActionType() == ActionType.START_SERVER) {
returnType = startServer(action);
}
else if (action.getActionType() == ActionType.CREATE_SERVER) {
returnType = createServer(action);
}
else if (action.getActionType() == ActionType.STOP_SERVER) {
returnType = stopServer(action);
}
return returnType;
}
private ActionDecision startServer(ScalingActionContext action) {
// perform some action to start a server
return ActionDecision.DEFAULT_ACTION;
}
private ActionDecision createServer(ScalingActionContext action) {
// perform some action to create a server
return ActionDecision.DEFAULT_ACTION;
}
private ActionDecision stopServer(ScalingActionContext action) {
// perform some action to stop a server
return ActionDecision.DEFAULT_ACTION;
}
}
- Dans le projet ScalingSPISampleBundle, ouvrez la classe Activator
et éditez la méthode start(BundleContext) pour ajouter le code enregistrant le nouveau service de programme d'écoute.
public void start(BundleContext context) throws Exception {
final Hashtable<String, Object> properties = new Hashtable<String, Object>();
ScalingSPISamplePlugin scalingSPISamplePlugin = new ScalingSPISamplePlugin();
context.registerService(ScalingActionPlugin.class, scalingSPISamplePlugin, properties);
}
Si vous êtes invité à importer une mappe de hachage (HashMap), choisissez d'importer java.util.HashMap.
- Cliquez avec le bouton droit sur le projet ScalingSPISampleFeature,
puis cliquez sur Install Feature afin d'installer la fonction dans l'exécution Liberty.
L'option de menu Install Feature se trouve dans la vue Enterprise Explorer de la perspective Java EE.
- Editez le fichier server.xml pour activer ScalingSPISampleFeature.
...
<featureManager>
...
<feature>scalingController-1.0</feature>
<feature>usr:ScalingSPISampleFeature</feature>
</featureManager>
...